Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ethers-decode-error

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ethers-decode-error - npm Package Compare versions

Comparing version 2.1.1 to 2.1.2

2

dist/error-decoder.js

@@ -1,2 +0,2 @@

var r=require("ethers");function e(){return e=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r},e.apply(this,arguments)}function n(r,e){(null==e||e>r.length)&&(e=r.length);for(var n=0,t=new Array(e);n<e;n++)t[n]=r[n];return t}var t,a="0x08c379a0",o="0x4e487b71";!function(r){r.EmptyError="EmptyError",r.RevertError="RevertError",r.PanicError="PanicError",r.CustomError="CustomError",r.UserRejectError="UserRejectError",r.RpcError="RpcError",r.UnknownError="UnknownError"}(t||(t={}));var i=function(r,e){return r&&""!==r.trim()?r:e},u=function(n){var t=n.data,a=n.fragment,o=n.args,u=n.selector,c=n.name,s={type:n.type,reason:i(n.reason,null),data:null!=t?t:null,fragment:null,args:null!=o?o:new r.Result,selector:null!=u?u:null,name:null!=c?c:null,signature:null};return a&&(s=e({},s,new r.ErrorDescription(a,a.selector,o))),s},c=function(r){var e=r.data,n=r.name;return u({type:t.UnknownError,reason:i(r.reason,"Unknown error"),data:e,name:n})},s=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r){return"0x"===r},e.handle=function(r){return u({type:t.EmptyError,data:{data:r}.data})},r}(),l=/*#__PURE__*/function(){function e(){}var n=e.prototype;return n.predicate=function(r){return null==r?void 0:r.startsWith(a)},n.handle=function(e){var n,a=e.slice(10),o=new r.AbiCoder;try{var i=r.ErrorFragment.from("Error(string)"),s=o.decode(i.inputs,"0x"+a);return u({type:t.RevertError,reason:(n={data:e,fragment:i,reason:s[0],args:s}).reason,data:n.data,fragment:n.fragment,args:n.args})}catch(r){return c({reason:"Unknown error returned",data:e})}},e}(),d=/*#__PURE__*/function(){function e(){}var n=e.prototype;return n.predicate=function(r){return null==r?void 0:r.startsWith(o)},n.handle=function(e){var n,a=e.slice(10),o=new r.AbiCoder;try{var i,s=r.ErrorFragment.from("Panic(uint256)"),l=o.decode(s.inputs,"0x"+a),d=null!=(i=function(r){switch(r){case 0x0n:return"Generic compiler inserted panic";case 0x1n:return"Assertion error";case 0x11n:return"Arithmetic operation underflowed or overflowed outside of an unchecked block";case 0x12n:return"Division or modulo division by zero";case 0x21n:return"Tried to convert a value into an enum, but the value was too big or negative";case 0x22n:return"Incorrectly encoded storage byte array";case 0x31n:return".pop() was called on an empty array";case 0x32n:return"Array accessed at an out-of-bounds or negative index";case 0x41n:return"Too much memory was allocated, or an array was created that is too large";case 0x51n:return"Called a zero-initialized variable of internal function type"}}(l[0]))?i:"Unknown panic code";return u({type:t.PanicError,reason:(n={data:e,fragment:s,reason:d,args:l}).reason,data:n.data,args:n.args})}catch(r){return c({reason:"Unknown panic error",data:e})}},e}(),f=/*#__PURE__*/function(){function r(){}var n=r.prototype;return n.predicate=function(r){return r&&"0x"!==r&&!(null!=r&&r.startsWith(a))&&!(null!=r&&r.startsWith(o))},n.handle=function(r,n){var a=n.errorInterface,o={data:r};if(a){var c=a.parseError(r);c&&(o=e({},o,{fragment:c.fragment,reason:c.name,args:c.args}))}return function(r){var e=r.data,n=r.reason,a=r.fragment,o=r.args,c=e.slice(0,10);return u({type:t.CustomError,reason:i(n,"No ABI for custom error "+c),data:e,fragment:a,args:o,selector:c,name:c})}(o)},r}(),v=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r,e){var n;return!r&&(null==e||null==(n=e.message)?void 0:n.includes("rejected transaction"))},e.handle=function(r,e){var n,a,o,c;return c=void 0===(o=(a={data:null,reason:null!=(n=e.error.message)?n:"The transaction was rejected"}).data)?null:o,u({type:t.UserRejectError,reason:i(a.reason,"User has rejected the transaction"),data:c})},r}(),m=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r,e){var n;return!r&&e.message&&!(null!=e&&null!=(n=e.message)&&n.includes("rejected transaction"))&&void 0!==e.code},e.handle=function(r,e){var n,a,o,c=e.error;return o=(n={data:null,name:c.code,reason:c.message}).name,u({type:t.RpcError,reason:i(n.reason,"Error from JSON RPC provider"),data:null,name:null!=(a=null==o?void 0:o.toString())?a:null})},r}();exports.ErrorDecoder=/*#__PURE__*/function(){function t(r,e){this.errorInterface=void 0,this.errorHandlers=[],this.errorInterface=e,this.errorHandlers=r.map(function(r){return{predicate:r.predicate,handle:r.handle}})}var a=t.prototype;return a.getContractOrTransactionError=function(r){try{var e=r.receipt;return e?Promise.resolve(this.getTransactionError(e)).then(function(e){return e||r}):Promise.resolve(r)}catch(r){return Promise.reject(r)}},a.getTransactionError=function(r){try{if(!r||0!==r.status)return Promise.resolve(void 0);var n=r.provider;return Promise.resolve(n.getTransaction(r.hash)).then(function(r){return function(t,a){try{var o=Promise.resolve(n.call(e({},r,{maxFeePerGas:void 0,maxPriorityFeePerGas:void 0}))).then(function(){return null})}catch(r){return r}return o&&o.then?o.then(void 0,function(r){return r}):o}()})}catch(r){return Promise.reject(r)}},a.getDataFromError=function(r){var e,n,t=null!=(e=r.data)?e:null==(n=r.error)?void 0:n.data;if(void 0!==t){var a="string"==typeof t?t:t.data;if("object"==typeof a&&a.data&&(a=a.data),void 0!==a&&"string"==typeof a)return a}},a.decode=function(r){try{var e,t=this;return r instanceof Error?Promise.resolve(t.getContractOrTransactionError(r)).then(function(r){for(var e,a,o=t.getDataFromError(r),i=function(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return(t=t.call(r)).next.bind(t);if(Array.isArray(r)||(t=function(r,e){if(r){if("string"==typeof r)return n(r,e);var t=Object.prototype.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?n(r,e):void 0}}(r))){t&&(r=t);var a=0;return function(){return a>=r.length?{done:!0}:{done:!1,value:r[a++]}}}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.errorHandlers);!(a=i()).done;){var u=a.value,s=u.handle;if((0,u.predicate)(o,r))return s(o,{errorInterface:t.errorInterface,error:r})}return c({data:o,reason:null!=(e=null==r?void 0:r.message)?e:"Unexpected error",name:null==r?void 0:r.name})}):Promise.resolve(c({data:void 0,reason:null!=(e=r.message)?e:"Invalid error"}))}catch(r){return Promise.reject(r)}},t.create=function(e,n){void 0===n&&(n={});var a,o=n.additionalErrorHandlers;if(e){var i=e.flatMap(function(e){return e instanceof r.Interface?e.fragments.filter(function(e){return r.ErrorFragment.isFragment(e)}):e.filter(function(e){return"error"===e.type||r.ErrorFragment.isFragment(e)})});a=new r.Interface(i)}return new t([new s,new l,new d,new f,new v,new m].concat(null!=o?o:[]),a)},t}();
var r=require("ethers");function e(){return e=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r},e.apply(this,arguments)}function n(r,e){(null==e||e>r.length)&&(e=r.length);for(var n=0,t=new Array(e);n<e;n++)t[n]=r[n];return t}var t,a="0x08c379a0",o="0x4e487b71";!function(r){r.EmptyError="EmptyError",r.RevertError="RevertError",r.PanicError="PanicError",r.CustomError="CustomError",r.UserRejectError="UserRejectError",r.RpcError="RpcError",r.UnknownError="UnknownError"}(t||(t={}));var i=function(r,e){return r&&""!==r.trim()?r:e},u=function(n){var t=n.data,a=n.fragment,o=n.args,u=n.selector,c=n.name,s={type:n.type,reason:i(n.reason,null),data:null!=t?t:null,fragment:null,args:null!=o?o:new r.Result,selector:null!=u?u:null,name:null!=c?c:null,signature:null};return a&&(s=e({},s,new r.ErrorDescription(a,a.selector,o))),s},c=function(r){var e=r.data,n=r.name;return u({type:t.UnknownError,reason:i(r.reason,"Unknown error"),data:e,name:n})},s=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r){return"0x"===r},e.handle=function(r){return u({type:t.EmptyError,data:{data:r}.data})},r}(),l=/*#__PURE__*/function(){function e(){}var n=e.prototype;return n.predicate=function(r){return null==r?void 0:r.startsWith(a)},n.handle=function(e){var n,a=e.slice(10),o=new r.AbiCoder;try{var i=r.ErrorFragment.from("Error(string)"),s=o.decode(i.inputs,"0x"+a);return u({type:t.RevertError,reason:(n={data:e,fragment:i,reason:s[0],args:s}).reason,data:n.data,fragment:n.fragment,args:n.args})}catch(r){return c({reason:"Unknown error returned",data:e})}},e}(),d=/*#__PURE__*/function(){function e(){}var n=e.prototype;return n.predicate=function(r){return null==r?void 0:r.startsWith(o)},n.handle=function(e){var n,a=e.slice(10),o=new r.AbiCoder;try{var i,s=r.ErrorFragment.from("Panic(uint256)"),l=o.decode(s.inputs,"0x"+a),d=null!=(i=function(r){switch(r){case 0x0n:return"Generic compiler inserted panic";case 0x1n:return"Assertion error";case 0x11n:return"Arithmetic operation underflowed or overflowed outside of an unchecked block";case 0x12n:return"Division or modulo division by zero";case 0x21n:return"Tried to convert a value into an enum, but the value was too big or negative";case 0x22n:return"Incorrectly encoded storage byte array";case 0x31n:return".pop() was called on an empty array";case 0x32n:return"Array accessed at an out-of-bounds or negative index";case 0x41n:return"Too much memory was allocated, or an array was created that is too large";case 0x51n:return"Called a zero-initialized variable of internal function type"}}(l[0]))?i:"Unknown panic code";return u({type:t.PanicError,reason:(n={data:e,fragment:s,reason:d,args:l}).reason,data:n.data,args:n.args})}catch(r){return c({reason:"Unknown panic error",data:e})}},e}(),f=/*#__PURE__*/function(){function r(){}var n=r.prototype;return n.predicate=function(r){return r&&"0x"!==r&&!(null!=r&&r.startsWith(a))&&!(null!=r&&r.startsWith(o))},n.handle=function(r,n){var a=n.errorInterface,o={data:r};if(a){var c=a.parseError(r);c&&(o=e({},o,{fragment:c.fragment,reason:c.name,args:c.args}))}return function(r){var e=r.data,n=r.reason,a=r.fragment,o=r.args,c=e.slice(0,10);return u({type:t.CustomError,reason:i(n,"No ABI for custom error "+c),data:e,fragment:a,args:o,selector:c,name:c})}(o)},r}(),v=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r,e){var n;return!r&&(null==e||null==(n=e.message)?void 0:n.includes("rejected transaction"))},e.handle=function(r,e){var n,a,o,c;return c=void 0===(o=(a={data:null,reason:null!=(n=e.error.message)?n:"The transaction was rejected"}).data)?null:o,u({type:t.UserRejectError,reason:i(a.reason,"User has rejected the transaction"),data:c})},r}(),m=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r,e){var n;return!r&&e.message&&!(null!=e&&null!=(n=e.message)&&n.includes("rejected transaction"))&&void 0!==e.code},e.handle=function(r,e){var n,a,o,c,s,l,d,f=e.error,v=null!=(n=null!=(a=null==(o=f.info)||null==(c=o.error)?void 0:c.message)?a:f.shortMessage)?n:f.message;return d=(s={data:null,name:f.code,reason:v}).name,u({type:t.RpcError,reason:i(s.reason,"Error from JSON RPC provider"),data:null,name:null!=(l=null==d?void 0:d.toString())?l:null})},r}();exports.ErrorDecoder=/*#__PURE__*/function(){function t(r,e){this.errorInterface=void 0,this.errorHandlers=[],this.errorInterface=e,this.errorHandlers=r.map(function(r){return{predicate:r.predicate,handle:r.handle}})}var a=t.prototype;return a.getContractOrTransactionError=function(r){try{var e=r.receipt;return e?Promise.resolve(this.getTransactionError(e)).then(function(e){return e||r}):Promise.resolve(r)}catch(r){return Promise.reject(r)}},a.getTransactionError=function(r){try{if(!r||0!==r.status)return Promise.resolve(void 0);var n=r.provider;return Promise.resolve(n.getTransaction(r.hash)).then(function(r){return function(t,a){try{var o=Promise.resolve(n.call(e({},r,{maxFeePerGas:void 0,maxPriorityFeePerGas:void 0}))).then(function(){return null})}catch(r){return r}return o&&o.then?o.then(void 0,function(r){return r}):o}()})}catch(r){return Promise.reject(r)}},a.getDataFromError=function(r){var e,n,t=null!=(e=r.data)?e:null==(n=r.error)?void 0:n.data;if(void 0!==t){var a="string"==typeof t?t:t.data;if("object"==typeof a&&a.data&&(a=a.data),void 0!==a&&"string"==typeof a)return a}},a.decode=function(r){try{var e,t=this;return r instanceof Error?Promise.resolve(t.getContractOrTransactionError(r)).then(function(r){for(var e,a,o=t.getDataFromError(r),i=function(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return(t=t.call(r)).next.bind(t);if(Array.isArray(r)||(t=function(r,e){if(r){if("string"==typeof r)return n(r,e);var t=Object.prototype.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?n(r,e):void 0}}(r))){t&&(r=t);var a=0;return function(){return a>=r.length?{done:!0}:{done:!1,value:r[a++]}}}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.errorHandlers);!(a=i()).done;){var u=a.value,s=u.handle;if((0,u.predicate)(o,r))return s(o,{errorInterface:t.errorInterface,error:r})}return c({data:o,reason:null!=(e=null==r?void 0:r.message)?e:"Unexpected error",name:null==r?void 0:r.name})}):Promise.resolve(c({data:void 0,reason:null!=(e=r.message)?e:"Invalid error"}))}catch(r){return Promise.reject(r)}},t.create=function(e,n){void 0===n&&(n={});var a,o=n.additionalErrorHandlers;if(e){var i=e.flatMap(function(e){return e instanceof r.Interface?e.fragments.filter(function(e){return r.ErrorFragment.isFragment(e)}):e.filter(function(e){return"error"===e.type||r.ErrorFragment.isFragment(e)})});a=new r.Interface(i)}return new t([new s,new l,new d,new f,new v,new m].concat(null!=o?o:[]),a)},t}();
//# sourceMappingURL=error-decoder.js.map

@@ -1,2 +0,2 @@

!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("ethers")):"function"==typeof define&&define.amd?define(["exports","ethers"],e):e((r||self).ethersDecodeError={},r.ethers)}(this,function(r,e){function n(){return n=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r},n.apply(this,arguments)}function t(r,e){(null==e||e>r.length)&&(e=r.length);for(var n=0,t=new Array(e);n<e;n++)t[n]=r[n];return t}var a,o="0x08c379a0",i="0x4e487b71";!function(r){r.EmptyError="EmptyError",r.RevertError="RevertError",r.PanicError="PanicError",r.CustomError="CustomError",r.UserRejectError="UserRejectError",r.RpcError="RpcError",r.UnknownError="UnknownError"}(a||(a={}));var u=function(r,e){return r&&""!==r.trim()?r:e},c=function(r){var t=r.data,a=r.fragment,o=r.args,i=r.selector,c=r.name,s={type:r.type,reason:u(r.reason,null),data:null!=t?t:null,fragment:null,args:null!=o?o:new e.Result,selector:null!=i?i:null,name:null!=c?c:null,signature:null};return a&&(s=n({},s,new e.ErrorDescription(a,a.selector,o))),s},s=function(r){var e=r.data,n=r.name;return c({type:a.UnknownError,reason:u(r.reason,"Unknown error"),data:e,name:n})},l=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r){return"0x"===r},e.handle=function(r){return c({type:a.EmptyError,data:{data:r}.data})},r}(),d=/*#__PURE__*/function(){function r(){}var n=r.prototype;return n.predicate=function(r){return null==r?void 0:r.startsWith(o)},n.handle=function(r){var n,t=r.slice(10),o=new e.AbiCoder;try{var i=e.ErrorFragment.from("Error(string)"),u=o.decode(i.inputs,"0x"+t);return c({type:a.RevertError,reason:(n={data:r,fragment:i,reason:u[0],args:u}).reason,data:n.data,fragment:n.fragment,args:n.args})}catch(e){return s({reason:"Unknown error returned",data:r})}},r}(),f=/*#__PURE__*/function(){function r(){}var n=r.prototype;return n.predicate=function(r){return null==r?void 0:r.startsWith(i)},n.handle=function(r){var n,t=r.slice(10),o=new e.AbiCoder;try{var i,u=e.ErrorFragment.from("Panic(uint256)"),l=o.decode(u.inputs,"0x"+t),d=null!=(i=function(r){switch(r){case 0x0n:return"Generic compiler inserted panic";case 0x1n:return"Assertion error";case 0x11n:return"Arithmetic operation underflowed or overflowed outside of an unchecked block";case 0x12n:return"Division or modulo division by zero";case 0x21n:return"Tried to convert a value into an enum, but the value was too big or negative";case 0x22n:return"Incorrectly encoded storage byte array";case 0x31n:return".pop() was called on an empty array";case 0x32n:return"Array accessed at an out-of-bounds or negative index";case 0x41n:return"Too much memory was allocated, or an array was created that is too large";case 0x51n:return"Called a zero-initialized variable of internal function type"}}(l[0]))?i:"Unknown panic code";return c({type:a.PanicError,reason:(n={data:r,fragment:u,reason:d,args:l}).reason,data:n.data,args:n.args})}catch(e){return s({reason:"Unknown panic error",data:r})}},r}(),v=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r){return r&&"0x"!==r&&!(null!=r&&r.startsWith(o))&&!(null!=r&&r.startsWith(i))},e.handle=function(r,e){var t=e.errorInterface,o={data:r};if(t){var i=t.parseError(r);i&&(o=n({},o,{fragment:i.fragment,reason:i.name,args:i.args}))}return function(r){var e=r.data,n=r.reason,t=r.fragment,o=r.args,i=e.slice(0,10);return c({type:a.CustomError,reason:u(n,"No ABI for custom error "+i),data:e,fragment:t,args:o,selector:i,name:i})}(o)},r}(),m=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r,e){var n;return!r&&(null==e||null==(n=e.message)?void 0:n.includes("rejected transaction"))},e.handle=function(r,e){var n,t,o,i;return i=void 0===(o=(t={data:null,reason:null!=(n=e.error.message)?n:"The transaction was rejected"}).data)?null:o,c({type:a.UserRejectError,reason:u(t.reason,"User has rejected the transaction"),data:i})},r}(),p=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r,e){var n;return!r&&e.message&&!(null!=e&&null!=(n=e.message)&&n.includes("rejected transaction"))&&void 0!==e.code},e.handle=function(r,e){var n,t,o,i=e.error;return o=(n={data:null,name:i.code,reason:i.message}).name,c({type:a.RpcError,reason:u(n.reason,"Error from JSON RPC provider"),data:null,name:null!=(t=null==o?void 0:o.toString())?t:null})},r}();r.ErrorDecoder=/*#__PURE__*/function(){function r(r,e){this.errorInterface=void 0,this.errorHandlers=[],this.errorInterface=e,this.errorHandlers=r.map(function(r){return{predicate:r.predicate,handle:r.handle}})}var a=r.prototype;return a.getContractOrTransactionError=function(r){try{var e=r.receipt;return e?Promise.resolve(this.getTransactionError(e)).then(function(e){return e||r}):Promise.resolve(r)}catch(r){return Promise.reject(r)}},a.getTransactionError=function(r){try{if(!r||0!==r.status)return Promise.resolve(void 0);var e=r.provider;return Promise.resolve(e.getTransaction(r.hash)).then(function(r){return function(t,a){try{var o=Promise.resolve(e.call(n({},r,{maxFeePerGas:void 0,maxPriorityFeePerGas:void 0}))).then(function(){return null})}catch(r){return r}return o&&o.then?o.then(void 0,function(r){return r}):o}()})}catch(r){return Promise.reject(r)}},a.getDataFromError=function(r){var e,n,t=null!=(e=r.data)?e:null==(n=r.error)?void 0:n.data;if(void 0!==t){var a="string"==typeof t?t:t.data;if("object"==typeof a&&a.data&&(a=a.data),void 0!==a&&"string"==typeof a)return a}},a.decode=function(r){try{var e,n=this;return r instanceof Error?Promise.resolve(n.getContractOrTransactionError(r)).then(function(r){for(var e,a,o=n.getDataFromError(r),i=function(r,e){var n="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(n)return(n=n.call(r)).next.bind(n);if(Array.isArray(r)||(n=function(r,e){if(r){if("string"==typeof r)return t(r,e);var n=Object.prototype.toString.call(r).slice(8,-1);return"Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n?Array.from(r):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(r,e):void 0}}(r))){n&&(r=n);var a=0;return function(){return a>=r.length?{done:!0}:{done:!1,value:r[a++]}}}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.errorHandlers);!(a=i()).done;){var u=a.value,c=u.handle;if((0,u.predicate)(o,r))return c(o,{errorInterface:n.errorInterface,error:r})}return s({data:o,reason:null!=(e=null==r?void 0:r.message)?e:"Unexpected error",name:null==r?void 0:r.name})}):Promise.resolve(s({data:void 0,reason:null!=(e=r.message)?e:"Invalid error"}))}catch(r){return Promise.reject(r)}},r.create=function(n,t){void 0===t&&(t={});var a,o=t.additionalErrorHandlers;if(n){var i=n.flatMap(function(r){return r instanceof e.Interface?r.fragments.filter(function(r){return e.ErrorFragment.isFragment(r)}):r.filter(function(r){return"error"===r.type||e.ErrorFragment.isFragment(r)})});a=new e.Interface(i)}return new r([new l,new d,new f,new v,new m,new p].concat(null!=o?o:[]),a)},r}()});
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("ethers")):"function"==typeof define&&define.amd?define(["exports","ethers"],e):e((r||self).ethersDecodeError={},r.ethers)}(this,function(r,e){function n(){return n=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r},n.apply(this,arguments)}function t(r,e){(null==e||e>r.length)&&(e=r.length);for(var n=0,t=new Array(e);n<e;n++)t[n]=r[n];return t}var a,o="0x08c379a0",i="0x4e487b71";!function(r){r.EmptyError="EmptyError",r.RevertError="RevertError",r.PanicError="PanicError",r.CustomError="CustomError",r.UserRejectError="UserRejectError",r.RpcError="RpcError",r.UnknownError="UnknownError"}(a||(a={}));var u=function(r,e){return r&&""!==r.trim()?r:e},s=function(r){var t=r.data,a=r.fragment,o=r.args,i=r.selector,s=r.name,c={type:r.type,reason:u(r.reason,null),data:null!=t?t:null,fragment:null,args:null!=o?o:new e.Result,selector:null!=i?i:null,name:null!=s?s:null,signature:null};return a&&(c=n({},c,new e.ErrorDescription(a,a.selector,o))),c},c=function(r){var e=r.data,n=r.name;return s({type:a.UnknownError,reason:u(r.reason,"Unknown error"),data:e,name:n})},l=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r){return"0x"===r},e.handle=function(r){return s({type:a.EmptyError,data:{data:r}.data})},r}(),d=/*#__PURE__*/function(){function r(){}var n=r.prototype;return n.predicate=function(r){return null==r?void 0:r.startsWith(o)},n.handle=function(r){var n,t=r.slice(10),o=new e.AbiCoder;try{var i=e.ErrorFragment.from("Error(string)"),u=o.decode(i.inputs,"0x"+t);return s({type:a.RevertError,reason:(n={data:r,fragment:i,reason:u[0],args:u}).reason,data:n.data,fragment:n.fragment,args:n.args})}catch(e){return c({reason:"Unknown error returned",data:r})}},r}(),f=/*#__PURE__*/function(){function r(){}var n=r.prototype;return n.predicate=function(r){return null==r?void 0:r.startsWith(i)},n.handle=function(r){var n,t=r.slice(10),o=new e.AbiCoder;try{var i,u=e.ErrorFragment.from("Panic(uint256)"),l=o.decode(u.inputs,"0x"+t),d=null!=(i=function(r){switch(r){case 0x0n:return"Generic compiler inserted panic";case 0x1n:return"Assertion error";case 0x11n:return"Arithmetic operation underflowed or overflowed outside of an unchecked block";case 0x12n:return"Division or modulo division by zero";case 0x21n:return"Tried to convert a value into an enum, but the value was too big or negative";case 0x22n:return"Incorrectly encoded storage byte array";case 0x31n:return".pop() was called on an empty array";case 0x32n:return"Array accessed at an out-of-bounds or negative index";case 0x41n:return"Too much memory was allocated, or an array was created that is too large";case 0x51n:return"Called a zero-initialized variable of internal function type"}}(l[0]))?i:"Unknown panic code";return s({type:a.PanicError,reason:(n={data:r,fragment:u,reason:d,args:l}).reason,data:n.data,args:n.args})}catch(e){return c({reason:"Unknown panic error",data:r})}},r}(),v=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r){return r&&"0x"!==r&&!(null!=r&&r.startsWith(o))&&!(null!=r&&r.startsWith(i))},e.handle=function(r,e){var t=e.errorInterface,o={data:r};if(t){var i=t.parseError(r);i&&(o=n({},o,{fragment:i.fragment,reason:i.name,args:i.args}))}return function(r){var e=r.data,n=r.reason,t=r.fragment,o=r.args,i=e.slice(0,10);return s({type:a.CustomError,reason:u(n,"No ABI for custom error "+i),data:e,fragment:t,args:o,selector:i,name:i})}(o)},r}(),m=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r,e){var n;return!r&&(null==e||null==(n=e.message)?void 0:n.includes("rejected transaction"))},e.handle=function(r,e){var n,t,o,i;return i=void 0===(o=(t={data:null,reason:null!=(n=e.error.message)?n:"The transaction was rejected"}).data)?null:o,s({type:a.UserRejectError,reason:u(t.reason,"User has rejected the transaction"),data:i})},r}(),p=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r,e){var n;return!r&&e.message&&!(null!=e&&null!=(n=e.message)&&n.includes("rejected transaction"))&&void 0!==e.code},e.handle=function(r,e){var n,t,o,i,c,l,d,f=e.error,v=null!=(n=null!=(t=null==(o=f.info)||null==(i=o.error)?void 0:i.message)?t:f.shortMessage)?n:f.message;return d=(c={data:null,name:f.code,reason:v}).name,s({type:a.RpcError,reason:u(c.reason,"Error from JSON RPC provider"),data:null,name:null!=(l=null==d?void 0:d.toString())?l:null})},r}();r.ErrorDecoder=/*#__PURE__*/function(){function r(r,e){this.errorInterface=void 0,this.errorHandlers=[],this.errorInterface=e,this.errorHandlers=r.map(function(r){return{predicate:r.predicate,handle:r.handle}})}var a=r.prototype;return a.getContractOrTransactionError=function(r){try{var e=r.receipt;return e?Promise.resolve(this.getTransactionError(e)).then(function(e){return e||r}):Promise.resolve(r)}catch(r){return Promise.reject(r)}},a.getTransactionError=function(r){try{if(!r||0!==r.status)return Promise.resolve(void 0);var e=r.provider;return Promise.resolve(e.getTransaction(r.hash)).then(function(r){return function(t,a){try{var o=Promise.resolve(e.call(n({},r,{maxFeePerGas:void 0,maxPriorityFeePerGas:void 0}))).then(function(){return null})}catch(r){return r}return o&&o.then?o.then(void 0,function(r){return r}):o}()})}catch(r){return Promise.reject(r)}},a.getDataFromError=function(r){var e,n,t=null!=(e=r.data)?e:null==(n=r.error)?void 0:n.data;if(void 0!==t){var a="string"==typeof t?t:t.data;if("object"==typeof a&&a.data&&(a=a.data),void 0!==a&&"string"==typeof a)return a}},a.decode=function(r){try{var e,n=this;return r instanceof Error?Promise.resolve(n.getContractOrTransactionError(r)).then(function(r){for(var e,a,o=n.getDataFromError(r),i=function(r,e){var n="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(n)return(n=n.call(r)).next.bind(n);if(Array.isArray(r)||(n=function(r,e){if(r){if("string"==typeof r)return t(r,e);var n=Object.prototype.toString.call(r).slice(8,-1);return"Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n?Array.from(r):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(r,e):void 0}}(r))){n&&(r=n);var a=0;return function(){return a>=r.length?{done:!0}:{done:!1,value:r[a++]}}}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.errorHandlers);!(a=i()).done;){var u=a.value,s=u.handle;if((0,u.predicate)(o,r))return s(o,{errorInterface:n.errorInterface,error:r})}return c({data:o,reason:null!=(e=null==r?void 0:r.message)?e:"Unexpected error",name:null==r?void 0:r.name})}):Promise.resolve(c({data:void 0,reason:null!=(e=r.message)?e:"Invalid error"}))}catch(r){return Promise.reject(r)}},r.create=function(n,t){void 0===t&&(t={});var a,o=t.additionalErrorHandlers;if(n){var i=n.flatMap(function(r){return r instanceof e.Interface?r.fragments.filter(function(r){return e.ErrorFragment.isFragment(r)}):r.filter(function(r){return"error"===r.type||e.ErrorFragment.isFragment(r)})});a=new e.Interface(i)}return new r([new l,new d,new f,new v,new m,new p].concat(null!=o?o:[]),a)},r}()});
//# sourceMappingURL=error-decoder.umd.js.map

@@ -1,2 +0,2 @@

var r,e=require("ethers");function n(){return n=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r},n.apply(this,arguments)}function t(r,e){(null==e||e>r.length)&&(e=r.length);for(var n=0,t=new Array(e);n<e;n++)t[n]=r[n];return t}exports.ErrorType=void 0,(r=exports.ErrorType||(exports.ErrorType={})).EmptyError="EmptyError",r.RevertError="RevertError",r.PanicError="PanicError",r.CustomError="CustomError",r.UserRejectError="UserRejectError",r.RpcError="RpcError",r.UnknownError="UnknownError";var a="0x08c379a0",o="0x4e487b71",i=function(r,e){return r&&""!==r.trim()?r:e},s=function(r){var t=r.data,a=r.fragment,o=r.args,s=r.selector,u=r.name,c={type:r.type,reason:i(r.reason,null),data:null!=t?t:null,fragment:null,args:null!=o?o:new e.Result,selector:null!=s?s:null,name:null!=u?u:null,signature:null};return a&&(c=n({},c,new e.ErrorDescription(a,a.selector,o))),c},u=function(r){var e=r.data,n=r.name;return s({type:exports.ErrorType.UnknownError,reason:i(r.reason,"Unknown error"),data:e,name:n})},c=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r){return"0x"===r},e.handle=function(r){return s({type:exports.ErrorType.EmptyError,data:{data:r}.data})},r}(),l=/*#__PURE__*/function(){function r(){}var n=r.prototype;return n.predicate=function(r){return null==r?void 0:r.startsWith(a)},n.handle=function(r){var n,t=r.slice(10),a=new e.AbiCoder;try{var o=e.ErrorFragment.from("Error(string)"),i=a.decode(o.inputs,"0x"+t);return n={data:r,fragment:o,reason:i[0],args:i},s({type:exports.ErrorType.RevertError,reason:n.reason,data:n.data,fragment:n.fragment,args:n.args})}catch(e){return u({reason:"Unknown error returned",data:r})}},r}(),d=/*#__PURE__*/function(){function r(){}var n=r.prototype;return n.predicate=function(r){return null==r?void 0:r.startsWith(o)},n.handle=function(r){var n,t=r.slice(10),a=new e.AbiCoder;try{var o,i=e.ErrorFragment.from("Panic(uint256)"),c=a.decode(i.inputs,"0x"+t);return n={data:r,fragment:i,reason:null!=(o=function(r){switch(r){case 0x0n:return"Generic compiler inserted panic";case 0x1n:return"Assertion error";case 0x11n:return"Arithmetic operation underflowed or overflowed outside of an unchecked block";case 0x12n:return"Division or modulo division by zero";case 0x21n:return"Tried to convert a value into an enum, but the value was too big or negative";case 0x22n:return"Incorrectly encoded storage byte array";case 0x31n:return".pop() was called on an empty array";case 0x32n:return"Array accessed at an out-of-bounds or negative index";case 0x41n:return"Too much memory was allocated, or an array was created that is too large";case 0x51n:return"Called a zero-initialized variable of internal function type"}}(c[0]))?o:"Unknown panic code",args:c},s({type:exports.ErrorType.PanicError,reason:n.reason,data:n.data,args:n.args})}catch(e){return u({reason:"Unknown panic error",data:r})}},r}(),f=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r){return r&&"0x"!==r&&!(null!=r&&r.startsWith(a))&&!(null!=r&&r.startsWith(o))},e.handle=function(r,e){var t=e.errorInterface,a={data:r};if(t){var o=t.parseError(r);o&&(a=n({},a,{fragment:o.fragment,reason:o.name,args:o.args}))}return function(r){var e=r.data,n=r.reason,t=r.fragment,a=r.args,o=e.slice(0,10);return s({type:exports.ErrorType.CustomError,reason:i(n,"No ABI for custom error "+o),data:e,fragment:t,args:a,selector:o,name:o})}(a)},r}(),p=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r,e){var n;return!r&&(null==e||null==(n=e.message)?void 0:n.includes("rejected transaction"))},e.handle=function(r,e){var n,t,a,o;return o=void 0===(a=(t={data:null,reason:null!=(n=e.error.message)?n:"The transaction was rejected"}).data)?null:a,s({type:exports.ErrorType.UserRejectError,reason:i(t.reason,"User has rejected the transaction"),data:o})},r}(),v=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r,e){var n;return!r&&e.message&&!(null!=e&&null!=(n=e.message)&&n.includes("rejected transaction"))&&void 0!==e.code},e.handle=function(r,e){var n,t,a,o=e.error;return a=(n={data:null,name:o.code,reason:o.message}).name,s({type:exports.ErrorType.RpcError,reason:i(n.reason,"Error from JSON RPC provider"),data:null,name:null!=(t=null==a?void 0:a.toString())?t:null})},r}();exports.ErrorDecoder=/*#__PURE__*/function(){function r(r,e){this.errorInterface=void 0,this.errorHandlers=[],this.errorInterface=e,this.errorHandlers=r.map(function(r){return{predicate:r.predicate,handle:r.handle}})}var a=r.prototype;return a.getContractOrTransactionError=function(r){try{var e=r.receipt;return e?Promise.resolve(this.getTransactionError(e)).then(function(e){return e||r}):Promise.resolve(r)}catch(r){return Promise.reject(r)}},a.getTransactionError=function(r){try{if(!r||0!==r.status)return Promise.resolve(void 0);var e=r.provider;return Promise.resolve(e.getTransaction(r.hash)).then(function(r){return function(t,a){try{var o=Promise.resolve(e.call(n({},r,{maxFeePerGas:void 0,maxPriorityFeePerGas:void 0}))).then(function(){return null})}catch(r){return r}return o&&o.then?o.then(void 0,function(r){return r}):o}()})}catch(r){return Promise.reject(r)}},a.getDataFromError=function(r){var e,n,t=null!=(e=r.data)?e:null==(n=r.error)?void 0:n.data;if(void 0!==t){var a="string"==typeof t?t:t.data;if("object"==typeof a&&a.data&&(a=a.data),void 0!==a&&"string"==typeof a)return a}},a.decode=function(r){try{var e,n=this;return r instanceof Error?Promise.resolve(n.getContractOrTransactionError(r)).then(function(r){for(var e,a,o=n.getDataFromError(r),i=function(r,e){var n="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(n)return(n=n.call(r)).next.bind(n);if(Array.isArray(r)||(n=function(r,e){if(r){if("string"==typeof r)return t(r,e);var n=Object.prototype.toString.call(r).slice(8,-1);return"Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n?Array.from(r):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(r,e):void 0}}(r))){n&&(r=n);var a=0;return function(){return a>=r.length?{done:!0}:{done:!1,value:r[a++]}}}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.errorHandlers);!(a=i()).done;){var s=a.value,c=s.handle;if((0,s.predicate)(o,r))return c(o,{errorInterface:n.errorInterface,error:r})}return u({data:o,reason:null!=(e=null==r?void 0:r.message)?e:"Unexpected error",name:null==r?void 0:r.name})}):Promise.resolve(u({data:void 0,reason:null!=(e=r.message)?e:"Invalid error"}))}catch(r){return Promise.reject(r)}},r.create=function(n,t){void 0===t&&(t={});var a,o=t.additionalErrorHandlers;if(n){var i=n.flatMap(function(r){return r instanceof e.Interface?r.fragments.filter(function(r){return e.ErrorFragment.isFragment(r)}):r.filter(function(r){return"error"===r.type||e.ErrorFragment.isFragment(r)})});a=new e.Interface(i)}return new r([new c,new l,new d,new f,new p,new v].concat(null!=o?o:[]),a)},r}();
var r,e=require("ethers");function n(){return n=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r},n.apply(this,arguments)}function t(r,e){(null==e||e>r.length)&&(e=r.length);for(var n=0,t=new Array(e);n<e;n++)t[n]=r[n];return t}exports.ErrorType=void 0,(r=exports.ErrorType||(exports.ErrorType={})).EmptyError="EmptyError",r.RevertError="RevertError",r.PanicError="PanicError",r.CustomError="CustomError",r.UserRejectError="UserRejectError",r.RpcError="RpcError",r.UnknownError="UnknownError";var o="0x08c379a0",a="0x4e487b71",i=function(r,e){return r&&""!==r.trim()?r:e},s=function(r){var t=r.data,o=r.fragment,a=r.args,s=r.selector,u=r.name,c={type:r.type,reason:i(r.reason,null),data:null!=t?t:null,fragment:null,args:null!=a?a:new e.Result,selector:null!=s?s:null,name:null!=u?u:null,signature:null};return o&&(c=n({},c,new e.ErrorDescription(o,o.selector,a))),c},u=function(r){var e=r.data,n=r.name;return s({type:exports.ErrorType.UnknownError,reason:i(r.reason,"Unknown error"),data:e,name:n})},c=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r){return"0x"===r},e.handle=function(r){return s({type:exports.ErrorType.EmptyError,data:{data:r}.data})},r}(),l=/*#__PURE__*/function(){function r(){}var n=r.prototype;return n.predicate=function(r){return null==r?void 0:r.startsWith(o)},n.handle=function(r){var n,t=r.slice(10),o=new e.AbiCoder;try{var a=e.ErrorFragment.from("Error(string)"),i=o.decode(a.inputs,"0x"+t);return n={data:r,fragment:a,reason:i[0],args:i},s({type:exports.ErrorType.RevertError,reason:n.reason,data:n.data,fragment:n.fragment,args:n.args})}catch(e){return u({reason:"Unknown error returned",data:r})}},r}(),d=/*#__PURE__*/function(){function r(){}var n=r.prototype;return n.predicate=function(r){return null==r?void 0:r.startsWith(a)},n.handle=function(r){var n,t=r.slice(10),o=new e.AbiCoder;try{var a,i=e.ErrorFragment.from("Panic(uint256)"),c=o.decode(i.inputs,"0x"+t);return n={data:r,fragment:i,reason:null!=(a=function(r){switch(r){case 0x0n:return"Generic compiler inserted panic";case 0x1n:return"Assertion error";case 0x11n:return"Arithmetic operation underflowed or overflowed outside of an unchecked block";case 0x12n:return"Division or modulo division by zero";case 0x21n:return"Tried to convert a value into an enum, but the value was too big or negative";case 0x22n:return"Incorrectly encoded storage byte array";case 0x31n:return".pop() was called on an empty array";case 0x32n:return"Array accessed at an out-of-bounds or negative index";case 0x41n:return"Too much memory was allocated, or an array was created that is too large";case 0x51n:return"Called a zero-initialized variable of internal function type"}}(c[0]))?a:"Unknown panic code",args:c},s({type:exports.ErrorType.PanicError,reason:n.reason,data:n.data,args:n.args})}catch(e){return u({reason:"Unknown panic error",data:r})}},r}(),f=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r){return r&&"0x"!==r&&!(null!=r&&r.startsWith(o))&&!(null!=r&&r.startsWith(a))},e.handle=function(r,e){var t=e.errorInterface,o={data:r};if(t){var a=t.parseError(r);a&&(o=n({},o,{fragment:a.fragment,reason:a.name,args:a.args}))}return function(r){var e=r.data,n=r.reason,t=r.fragment,o=r.args,a=e.slice(0,10);return s({type:exports.ErrorType.CustomError,reason:i(n,"No ABI for custom error "+a),data:e,fragment:t,args:o,selector:a,name:a})}(o)},r}(),p=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r,e){var n;return!r&&(null==e||null==(n=e.message)?void 0:n.includes("rejected transaction"))},e.handle=function(r,e){var n,t,o,a;return a=void 0===(o=(t={data:null,reason:null!=(n=e.error.message)?n:"The transaction was rejected"}).data)?null:o,s({type:exports.ErrorType.UserRejectError,reason:i(t.reason,"User has rejected the transaction"),data:a})},r}(),v=/*#__PURE__*/function(){function r(){}var e=r.prototype;return e.predicate=function(r,e){var n;return!r&&e.message&&!(null!=e&&null!=(n=e.message)&&n.includes("rejected transaction"))&&void 0!==e.code},e.handle=function(r,e){var n,t,o,a,u,c,l,d=e.error,f=null!=(n=null!=(t=null==(o=d.info)||null==(a=o.error)?void 0:a.message)?t:d.shortMessage)?n:d.message;return l=(u={data:null,name:d.code,reason:f}).name,s({type:exports.ErrorType.RpcError,reason:i(u.reason,"Error from JSON RPC provider"),data:null,name:null!=(c=null==l?void 0:l.toString())?c:null})},r}();exports.ErrorDecoder=/*#__PURE__*/function(){function r(r,e){this.errorInterface=void 0,this.errorHandlers=[],this.errorInterface=e,this.errorHandlers=r.map(function(r){return{predicate:r.predicate,handle:r.handle}})}var o=r.prototype;return o.getContractOrTransactionError=function(r){try{var e=r.receipt;return e?Promise.resolve(this.getTransactionError(e)).then(function(e){return e||r}):Promise.resolve(r)}catch(r){return Promise.reject(r)}},o.getTransactionError=function(r){try{if(!r||0!==r.status)return Promise.resolve(void 0);var e=r.provider;return Promise.resolve(e.getTransaction(r.hash)).then(function(r){return function(t,o){try{var a=Promise.resolve(e.call(n({},r,{maxFeePerGas:void 0,maxPriorityFeePerGas:void 0}))).then(function(){return null})}catch(r){return r}return a&&a.then?a.then(void 0,function(r){return r}):a}()})}catch(r){return Promise.reject(r)}},o.getDataFromError=function(r){var e,n,t=null!=(e=r.data)?e:null==(n=r.error)?void 0:n.data;if(void 0!==t){var o="string"==typeof t?t:t.data;if("object"==typeof o&&o.data&&(o=o.data),void 0!==o&&"string"==typeof o)return o}},o.decode=function(r){try{var e,n=this;return r instanceof Error?Promise.resolve(n.getContractOrTransactionError(r)).then(function(r){for(var e,o,a=n.getDataFromError(r),i=function(r,e){var n="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(n)return(n=n.call(r)).next.bind(n);if(Array.isArray(r)||(n=function(r,e){if(r){if("string"==typeof r)return t(r,e);var n=Object.prototype.toString.call(r).slice(8,-1);return"Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n?Array.from(r):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(r,e):void 0}}(r))){n&&(r=n);var o=0;return function(){return o>=r.length?{done:!0}:{done:!1,value:r[o++]}}}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.errorHandlers);!(o=i()).done;){var s=o.value,c=s.handle;if((0,s.predicate)(a,r))return c(a,{errorInterface:n.errorInterface,error:r})}return u({data:a,reason:null!=(e=null==r?void 0:r.message)?e:"Unexpected error",name:null==r?void 0:r.name})}):Promise.resolve(u({data:void 0,reason:null!=(e=r.message)?e:"Invalid error"}))}catch(r){return Promise.reject(r)}},r.create=function(n,t){void 0===t&&(t={});var o,a=t.additionalErrorHandlers;if(n){var i=n.flatMap(function(r){return r instanceof e.Interface?r.fragments.filter(function(r){return e.ErrorFragment.isFragment(r)}):r.filter(function(r){return"error"===r.type||e.ErrorFragment.isFragment(r)})});o=new e.Interface(i)}return new r([new c,new l,new d,new f,new p,new v].concat(null!=a?a:[]),o)},r}();
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("ethers")):"function"==typeof define&&define.amd?define(["exports","ethers"],e):e((r||self).ethersDecodeError={},r.ethers)}(this,function(r,e){var n;function t(){return t=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r},t.apply(this,arguments)}function o(r,e){(null==e||e>r.length)&&(e=r.length);for(var n=0,t=new Array(e);n<e;n++)t[n]=r[n];return t}r.ErrorType=void 0,(n=r.ErrorType||(r.ErrorType={})).EmptyError="EmptyError",n.RevertError="RevertError",n.PanicError="PanicError",n.CustomError="CustomError",n.UserRejectError="UserRejectError",n.RpcError="RpcError",n.UnknownError="UnknownError";var a="0x08c379a0",i="0x4e487b71",u=function(r,e){return r&&""!==r.trim()?r:e},c=function(r){var n=r.data,o=r.fragment,a=r.args,i=r.selector,c=r.name,s={type:r.type,reason:u(r.reason,null),data:null!=n?n:null,fragment:null,args:null!=a?a:new e.Result,selector:null!=i?i:null,name:null!=c?c:null,signature:null};return o&&(s=t({},s,new e.ErrorDescription(o,o.selector,a))),s},s=function(e){var n=e.data,t=e.name;return c({type:r.ErrorType.UnknownError,reason:u(e.reason,"Unknown error"),data:n,name:t})},l=/*#__PURE__*/function(){function e(){}var n=e.prototype;return n.predicate=function(r){return"0x"===r},n.handle=function(e){return c({type:r.ErrorType.EmptyError,data:{data:e}.data})},e}(),d=/*#__PURE__*/function(){function n(){}var t=n.prototype;return t.predicate=function(r){return null==r?void 0:r.startsWith(a)},t.handle=function(n){var t,o=n.slice(10),a=new e.AbiCoder;try{var i=e.ErrorFragment.from("Error(string)"),u=a.decode(i.inputs,"0x"+o);return c({type:r.ErrorType.RevertError,reason:(t={data:n,fragment:i,reason:u[0],args:u}).reason,data:t.data,fragment:t.fragment,args:t.args})}catch(r){return s({reason:"Unknown error returned",data:n})}},n}(),f=/*#__PURE__*/function(){function n(){}var t=n.prototype;return t.predicate=function(r){return null==r?void 0:r.startsWith(i)},t.handle=function(n){var t,o=n.slice(10),a=new e.AbiCoder;try{var i,u=e.ErrorFragment.from("Panic(uint256)"),l=a.decode(u.inputs,"0x"+o),d=null!=(i=function(r){switch(r){case 0x0n:return"Generic compiler inserted panic";case 0x1n:return"Assertion error";case 0x11n:return"Arithmetic operation underflowed or overflowed outside of an unchecked block";case 0x12n:return"Division or modulo division by zero";case 0x21n:return"Tried to convert a value into an enum, but the value was too big or negative";case 0x22n:return"Incorrectly encoded storage byte array";case 0x31n:return".pop() was called on an empty array";case 0x32n:return"Array accessed at an out-of-bounds or negative index";case 0x41n:return"Too much memory was allocated, or an array was created that is too large";case 0x51n:return"Called a zero-initialized variable of internal function type"}}(l[0]))?i:"Unknown panic code";return c({type:r.ErrorType.PanicError,reason:(t={data:n,fragment:u,reason:d,args:l}).reason,data:t.data,args:t.args})}catch(r){return s({reason:"Unknown panic error",data:n})}},n}(),p=/*#__PURE__*/function(){function e(){}var n=e.prototype;return n.predicate=function(r){return r&&"0x"!==r&&!(null!=r&&r.startsWith(a))&&!(null!=r&&r.startsWith(i))},n.handle=function(e,n){var o=n.errorInterface,a={data:e};if(o){var i=o.parseError(e);i&&(a=t({},a,{fragment:i.fragment,reason:i.name,args:i.args}))}return function(e){var n=e.data,t=e.reason,o=e.fragment,a=e.args,i=n.slice(0,10);return c({type:r.ErrorType.CustomError,reason:u(t,"No ABI for custom error "+i),data:n,fragment:o,args:a,selector:i,name:i})}(a)},e}(),v=/*#__PURE__*/function(){function e(){}var n=e.prototype;return n.predicate=function(r,e){var n;return!r&&(null==e||null==(n=e.message)?void 0:n.includes("rejected transaction"))},n.handle=function(e,n){var t,o,a,i;return i=void 0===(a=(o={data:null,reason:null!=(t=n.error.message)?t:"The transaction was rejected"}).data)?null:a,c({type:r.ErrorType.UserRejectError,reason:u(o.reason,"User has rejected the transaction"),data:i})},e}(),m=/*#__PURE__*/function(){function e(){}var n=e.prototype;return n.predicate=function(r,e){var n;return!r&&e.message&&!(null!=e&&null!=(n=e.message)&&n.includes("rejected transaction"))&&void 0!==e.code},n.handle=function(e,n){var t,o,a,i=n.error;return a=(t={data:null,name:i.code,reason:i.message}).name,c({type:r.ErrorType.RpcError,reason:u(t.reason,"Error from JSON RPC provider"),data:null,name:null!=(o=null==a?void 0:a.toString())?o:null})},e}();r.ErrorDecoder=/*#__PURE__*/function(){function r(r,e){this.errorInterface=void 0,this.errorHandlers=[],this.errorInterface=e,this.errorHandlers=r.map(function(r){return{predicate:r.predicate,handle:r.handle}})}var n=r.prototype;return n.getContractOrTransactionError=function(r){try{var e=r.receipt;return e?Promise.resolve(this.getTransactionError(e)).then(function(e){return e||r}):Promise.resolve(r)}catch(r){return Promise.reject(r)}},n.getTransactionError=function(r){try{if(!r||0!==r.status)return Promise.resolve(void 0);var e=r.provider;return Promise.resolve(e.getTransaction(r.hash)).then(function(r){return function(n,o){try{var a=Promise.resolve(e.call(t({},r,{maxFeePerGas:void 0,maxPriorityFeePerGas:void 0}))).then(function(){return null})}catch(r){return r}return a&&a.then?a.then(void 0,function(r){return r}):a}()})}catch(r){return Promise.reject(r)}},n.getDataFromError=function(r){var e,n,t=null!=(e=r.data)?e:null==(n=r.error)?void 0:n.data;if(void 0!==t){var o="string"==typeof t?t:t.data;if("object"==typeof o&&o.data&&(o=o.data),void 0!==o&&"string"==typeof o)return o}},n.decode=function(r){try{var e,n=this;return r instanceof Error?Promise.resolve(n.getContractOrTransactionError(r)).then(function(r){for(var e,t,a=n.getDataFromError(r),i=function(r,e){var n="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(n)return(n=n.call(r)).next.bind(n);if(Array.isArray(r)||(n=function(r,e){if(r){if("string"==typeof r)return o(r,e);var n=Object.prototype.toString.call(r).slice(8,-1);return"Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n?Array.from(r):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(r,e):void 0}}(r))){n&&(r=n);var t=0;return function(){return t>=r.length?{done:!0}:{done:!1,value:r[t++]}}}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.errorHandlers);!(t=i()).done;){var u=t.value,c=u.handle;if((0,u.predicate)(a,r))return c(a,{errorInterface:n.errorInterface,error:r})}return s({data:a,reason:null!=(e=null==r?void 0:r.message)?e:"Unexpected error",name:null==r?void 0:r.name})}):Promise.resolve(s({data:void 0,reason:null!=(e=r.message)?e:"Invalid error"}))}catch(r){return Promise.reject(r)}},r.create=function(n,t){void 0===t&&(t={});var o,a=t.additionalErrorHandlers;if(n){var i=n.flatMap(function(r){return r instanceof e.Interface?r.fragments.filter(function(r){return e.ErrorFragment.isFragment(r)}):r.filter(function(r){return"error"===r.type||e.ErrorFragment.isFragment(r)})});o=new e.Interface(i)}return new r([new l,new d,new f,new p,new v,new m].concat(null!=a?a:[]),o)},r}()});
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("ethers")):"function"==typeof define&&define.amd?define(["exports","ethers"],e):e((r||self).ethersDecodeError={},r.ethers)}(this,function(r,e){var n;function t(){return t=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r},t.apply(this,arguments)}function o(r,e){(null==e||e>r.length)&&(e=r.length);for(var n=0,t=new Array(e);n<e;n++)t[n]=r[n];return t}r.ErrorType=void 0,(n=r.ErrorType||(r.ErrorType={})).EmptyError="EmptyError",n.RevertError="RevertError",n.PanicError="PanicError",n.CustomError="CustomError",n.UserRejectError="UserRejectError",n.RpcError="RpcError",n.UnknownError="UnknownError";var a="0x08c379a0",i="0x4e487b71",u=function(r,e){return r&&""!==r.trim()?r:e},s=function(r){var n=r.data,o=r.fragment,a=r.args,i=r.selector,s=r.name,c={type:r.type,reason:u(r.reason,null),data:null!=n?n:null,fragment:null,args:null!=a?a:new e.Result,selector:null!=i?i:null,name:null!=s?s:null,signature:null};return o&&(c=t({},c,new e.ErrorDescription(o,o.selector,a))),c},c=function(e){var n=e.data,t=e.name;return s({type:r.ErrorType.UnknownError,reason:u(e.reason,"Unknown error"),data:n,name:t})},l=/*#__PURE__*/function(){function e(){}var n=e.prototype;return n.predicate=function(r){return"0x"===r},n.handle=function(e){return s({type:r.ErrorType.EmptyError,data:{data:e}.data})},e}(),d=/*#__PURE__*/function(){function n(){}var t=n.prototype;return t.predicate=function(r){return null==r?void 0:r.startsWith(a)},t.handle=function(n){var t,o=n.slice(10),a=new e.AbiCoder;try{var i=e.ErrorFragment.from("Error(string)"),u=a.decode(i.inputs,"0x"+o);return s({type:r.ErrorType.RevertError,reason:(t={data:n,fragment:i,reason:u[0],args:u}).reason,data:t.data,fragment:t.fragment,args:t.args})}catch(r){return c({reason:"Unknown error returned",data:n})}},n}(),f=/*#__PURE__*/function(){function n(){}var t=n.prototype;return t.predicate=function(r){return null==r?void 0:r.startsWith(i)},t.handle=function(n){var t,o=n.slice(10),a=new e.AbiCoder;try{var i,u=e.ErrorFragment.from("Panic(uint256)"),l=a.decode(u.inputs,"0x"+o),d=null!=(i=function(r){switch(r){case 0x0n:return"Generic compiler inserted panic";case 0x1n:return"Assertion error";case 0x11n:return"Arithmetic operation underflowed or overflowed outside of an unchecked block";case 0x12n:return"Division or modulo division by zero";case 0x21n:return"Tried to convert a value into an enum, but the value was too big or negative";case 0x22n:return"Incorrectly encoded storage byte array";case 0x31n:return".pop() was called on an empty array";case 0x32n:return"Array accessed at an out-of-bounds or negative index";case 0x41n:return"Too much memory was allocated, or an array was created that is too large";case 0x51n:return"Called a zero-initialized variable of internal function type"}}(l[0]))?i:"Unknown panic code";return s({type:r.ErrorType.PanicError,reason:(t={data:n,fragment:u,reason:d,args:l}).reason,data:t.data,args:t.args})}catch(r){return c({reason:"Unknown panic error",data:n})}},n}(),p=/*#__PURE__*/function(){function e(){}var n=e.prototype;return n.predicate=function(r){return r&&"0x"!==r&&!(null!=r&&r.startsWith(a))&&!(null!=r&&r.startsWith(i))},n.handle=function(e,n){var o=n.errorInterface,a={data:e};if(o){var i=o.parseError(e);i&&(a=t({},a,{fragment:i.fragment,reason:i.name,args:i.args}))}return function(e){var n=e.data,t=e.reason,o=e.fragment,a=e.args,i=n.slice(0,10);return s({type:r.ErrorType.CustomError,reason:u(t,"No ABI for custom error "+i),data:n,fragment:o,args:a,selector:i,name:i})}(a)},e}(),v=/*#__PURE__*/function(){function e(){}var n=e.prototype;return n.predicate=function(r,e){var n;return!r&&(null==e||null==(n=e.message)?void 0:n.includes("rejected transaction"))},n.handle=function(e,n){var t,o,a,i;return i=void 0===(a=(o={data:null,reason:null!=(t=n.error.message)?t:"The transaction was rejected"}).data)?null:a,s({type:r.ErrorType.UserRejectError,reason:u(o.reason,"User has rejected the transaction"),data:i})},e}(),m=/*#__PURE__*/function(){function e(){}var n=e.prototype;return n.predicate=function(r,e){var n;return!r&&e.message&&!(null!=e&&null!=(n=e.message)&&n.includes("rejected transaction"))&&void 0!==e.code},n.handle=function(e,n){var t,o,a,i,c,l,d,f=n.error,p=null!=(t=null!=(o=null==(a=f.info)||null==(i=a.error)?void 0:i.message)?o:f.shortMessage)?t:f.message;return d=(c={data:null,name:f.code,reason:p}).name,s({type:r.ErrorType.RpcError,reason:u(c.reason,"Error from JSON RPC provider"),data:null,name:null!=(l=null==d?void 0:d.toString())?l:null})},e}();r.ErrorDecoder=/*#__PURE__*/function(){function r(r,e){this.errorInterface=void 0,this.errorHandlers=[],this.errorInterface=e,this.errorHandlers=r.map(function(r){return{predicate:r.predicate,handle:r.handle}})}var n=r.prototype;return n.getContractOrTransactionError=function(r){try{var e=r.receipt;return e?Promise.resolve(this.getTransactionError(e)).then(function(e){return e||r}):Promise.resolve(r)}catch(r){return Promise.reject(r)}},n.getTransactionError=function(r){try{if(!r||0!==r.status)return Promise.resolve(void 0);var e=r.provider;return Promise.resolve(e.getTransaction(r.hash)).then(function(r){return function(n,o){try{var a=Promise.resolve(e.call(t({},r,{maxFeePerGas:void 0,maxPriorityFeePerGas:void 0}))).then(function(){return null})}catch(r){return r}return a&&a.then?a.then(void 0,function(r){return r}):a}()})}catch(r){return Promise.reject(r)}},n.getDataFromError=function(r){var e,n,t=null!=(e=r.data)?e:null==(n=r.error)?void 0:n.data;if(void 0!==t){var o="string"==typeof t?t:t.data;if("object"==typeof o&&o.data&&(o=o.data),void 0!==o&&"string"==typeof o)return o}},n.decode=function(r){try{var e,n=this;return r instanceof Error?Promise.resolve(n.getContractOrTransactionError(r)).then(function(r){for(var e,t,a=n.getDataFromError(r),i=function(r,e){var n="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(n)return(n=n.call(r)).next.bind(n);if(Array.isArray(r)||(n=function(r,e){if(r){if("string"==typeof r)return o(r,e);var n=Object.prototype.toString.call(r).slice(8,-1);return"Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n?Array.from(r):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(r,e):void 0}}(r))){n&&(r=n);var t=0;return function(){return t>=r.length?{done:!0}:{done:!1,value:r[t++]}}}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.errorHandlers);!(t=i()).done;){var u=t.value,s=u.handle;if((0,u.predicate)(a,r))return s(a,{errorInterface:n.errorInterface,error:r})}return c({data:a,reason:null!=(e=null==r?void 0:r.message)?e:"Unexpected error",name:null==r?void 0:r.name})}):Promise.resolve(c({data:void 0,reason:null!=(e=r.message)?e:"Invalid error"}))}catch(r){return Promise.reject(r)}},r.create=function(n,t){void 0===t&&(t={});var o,a=t.additionalErrorHandlers;if(n){var i=n.flatMap(function(r){return r instanceof e.Interface?r.fragments.filter(function(r){return e.ErrorFragment.isFragment(r)}):r.filter(function(r){return"error"===r.type||e.ErrorFragment.isFragment(r)})});o=new e.Interface(i)}return new r([new l,new d,new f,new p,new v,new m].concat(null!=a?a:[]),o)},r}()});
//# sourceMappingURL=index.umd.js.map
{
"name": "ethers-decode-error",
"description": "Decode ethers.js smart contract errors into human-readable messages",
"version": "2.1.1",
"version": "2.1.2",
"author": {

@@ -6,0 +6,0 @@ "name": "superical",

@@ -31,3 +31,3 @@ # ethers-decode-error

> 💡 If you wish to use it with ethers v5 instead, please refer to the [v1 release](../../tree/1.x).
> 💡 If you wish to use it with ethers v5 instead, you may want to refer to [v1](../../tree/1.x).

@@ -46,11 +46,13 @@ ## Usage

The `create` method optionally accepts an array of ABI or contract interface objects as its first argument. Although the ABI is not required for normal reverts, it's recommended to supply the ABI or contract interfaces if you're expecting custom errors. See the examples in [Custom Errors](#custom-errors) section for more details.
The `create` method optionally accepts an array of ABI or contract interface objects as its first argument. Although the ABI is not required for regular reverts, it's recommended to supply the ABI or contract interfaces if you're expecting custom errors. See the examples in [Custom Error ABI and Interfaces](#custom-error-abi-and-interfaces) section for more details.
After creating the instance, you can repeatedly use the `decode` method throughout your code to decode error objects:
After creating the instance, you can reuse the `decode` method throughout your code to handle any errors thrown when interacting with smart contracts:
```typescript
import type { DecodedError } from 'ethers-decode-error'
try {
// Send a transaction that will revert
} catch (err) {
const decodedError: decodedError = await errorDecoder.decode(err)
const decodedError: DecodedError = await errorDecoder.decode(err)
console.log(`Revert reason: ${decodedError.reason}`)

@@ -77,3 +79,3 @@ }

These are the possible `ErrorType` that could be returned for the `type` property in the `DecodedError` object:
These are the possible `ErrorType` that could be returned as the `type` property in the `DecodedError` object:

@@ -104,5 +106,8 @@ | Type | Description |

} catch (err) {
const { reason } = await errorDecoder.decode(err)
const { reason, type } = await errorDecoder.decode(err)
// Prints "ERC20: transfer to the zero address"
console.log('Revert reason:', reason)
// Prints "true"
console.log(type === ErrorType.RevertError)
}

@@ -123,5 +128,8 @@ ```

} catch (err) {
const { reason } = await errorDecoder.decode(err)
const { reason, type } = await errorDecoder.decode(err)
// Prints "Arithmetic operation underflowed or overflowed outside of an unchecked block"
console.log('Panic message:', reason)
// Prints "true"
console.log(type === ErrorType.PanicError)
}

@@ -158,7 +166,10 @@ ```

const reason = customReasonMapper(decodedError)
// Prints "Invalid swap with token contract address 0xabcd."
console.log('Custom error reason:', reason)
// Prints "true"
console.log(type === ErrorType.CustomError)
}
const customReasonMapper = ({ name, args }: DecodedError): string => {
const customReasonMapper = ({ name, args, reason }: DecodedError): string => {
switch (name) {

@@ -170,4 +181,8 @@ case 'InvalidSwapToken':

return `Invalid swap with token contract address ${args['token']}.`
// You can map any other custom errors here
default:
return 'The transaction has reverted.'
// This handles the non-custom errors
return reason ?? 'An error has occurred'
}

@@ -177,7 +192,7 @@ }

#### Custom Errors ABI and Interfaces
#### Custom Error ABI and Interfaces
Although the ABI or ethers `Interface` object of the contract is not required when decoding normal revert errors, it is recommended to provide it if you're expecting custom errors. This is because the ABI or `Interface` object is needed to decode the custom error name and parameters.
> 💡 You can provide ABIs and `Interface` objects of multiple smart contracts where you expect custom errors. By doing so, you have a "universal" `ErrorDecoder` within your codebase capable of decoding any contract errors thrown. This decoder can then be reused throughout your code to handle any errors.
> 💡 It's much more convenient to supply the ABIs and Interface objects for all smart contracts your application may interact with when creating the `ErrorDecoder` instance. You will then only need a single `ErrorDecoder` instance that you can reuse across your codebase to handle any smart contract errors.

@@ -228,3 +243,3 @@ If you're expecting custom errors from multiple contracts or from external contracts called within your contract, you can provide the ABIs or interfaces of those contracts:

```typescript
const customReasonMapper = ({ name, args }: DecodedError): string => {
const customReasonMapper = ({ name, args, reason }: DecodedError): string => {
switch (name) {

@@ -241,3 +256,3 @@ // For custom errors with ABI, you can check the error name directly

default:
return 'The transaction has reverted.'
return reason ?? 'An error has occurred'
}

@@ -244,0 +259,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc