@bitzy-app/bitzy-sdk 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,2 +1,4 @@
1
- "use strict";var e=require("viem"),t=require("react"),r=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,n=Math.ceil,o=Math.floor,s="[BigNumber Error] ",i=s+"Number primitive has more than 15 significant digits: ",a=1e14,u=14,c=9007199254740991,l=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],f=1e7,d=1e9;function p(e){var t=0|e;return e>0||e===t?t:t-1}function h(e){for(var t,r,n=1,o=e.length,s=e[0]+"";n<o;){for(t=e[n++]+"",r=u-t.length;r--;t="0"+t);s+=t}for(o=s.length;48===s.charCodeAt(--o););return s.slice(0,o+1||1)}function g(e,t){var r,n,o=e.c,s=t.c,i=e.s,a=t.s,u=e.e,c=t.e;if(!i||!a)return null;if(r=o&&!o[0],n=s&&!s[0],r||n)return r?n?0:-a:i;if(i!=a)return i;if(r=i<0,n=u==c,!o||!s)return n?0:!o^r?1:-1;if(!n)return u>c^r?1:-1;for(a=(u=o.length)<(c=s.length)?u:c,i=0;i<a;i++)if(o[i]!=s[i])return o[i]>s[i]^r?1:-1;return u==c?0:u>c^r?1:-1}function m(e,t,r,n){if(e<t||e>r||e!==o(e))throw Error(s+(n||"Argument")+("number"==typeof e?e<t||e>r?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function E(e){var t=e.c.length-1;return p(e.e/u)==t&&e.c[t]%2!=0}function A(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function w(e,t,r){var n,o;if(t<0){for(o=r+".";++t;o+=r);e=o+e}else if(++t>(n=e.length)){for(o=r,t-=n;--t;o+=r);e+=o}else t<n&&(e=e.slice(0,t)+"."+e.slice(t));return e}var y=function e(t){var y,C,b,O,I,x,T,N,D,v,S=$.prototype={constructor:$,toString:null,valueOf:null},R=new $(1),B=20,P=4,_=-7,F=21,U=-1e7,k=1e7,L=!1,M=1,V=0,z={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},Q="0123456789abcdefghijklmnopqrstuvwxyz",G=!0;function $(e,t){var n,s,a,l,f,d,p,h,g=this;if(!(g instanceof $))return new $(e,t);if(null==t){if(e&&!0===e._isBigNumber)return g.s=e.s,void(!e.c||e.e>k?g.c=g.e=null:e.e<U?g.c=[g.e=0]:(g.e=e.e,g.c=e.c.slice()));if((d="number"==typeof e)&&0*e==0){if(g.s=1/e<0?(e=-e,-1):1,e===~~e){for(l=0,f=e;f>=10;f/=10,l++);return void(l>k?g.c=g.e=null:(g.e=l,g.c=[e]))}h=String(e)}else{if(!r.test(h=String(e)))return b(g,h,d);g.s=45==h.charCodeAt(0)?(h=h.slice(1),-1):1}(l=h.indexOf("."))>-1&&(h=h.replace(".","")),(f=h.search(/e/i))>0?(l<0&&(l=f),l+=+h.slice(f+1),h=h.substring(0,f)):l<0&&(l=h.length)}else{if(m(t,2,Q.length,"Base"),10==t&&G)return K(g=new $(e),B+g.e+1,P);if(h=String(e),d="number"==typeof e){if(0*e!=0)return b(g,h,d,t);if(g.s=1/e<0?(h=h.slice(1),-1):1,$.DEBUG&&h.replace(/^0\.0*|\./,"").length>15)throw Error(i+e)}else g.s=45===h.charCodeAt(0)?(h=h.slice(1),-1):1;for(n=Q.slice(0,t),l=f=0,p=h.length;f<p;f++)if(n.indexOf(s=h.charAt(f))<0){if("."==s){if(f>l){l=p;continue}}else if(!a&&(h==h.toUpperCase()&&(h=h.toLowerCase())||h==h.toLowerCase()&&(h=h.toUpperCase()))){a=!0,f=-1,l=0;continue}return b(g,String(e),d,t)}d=!1,(l=(h=C(h,t,10,g.s)).indexOf("."))>-1?h=h.replace(".",""):l=h.length}for(f=0;48===h.charCodeAt(f);f++);for(p=h.length;48===h.charCodeAt(--p););if(h=h.slice(f,++p)){if(p-=f,d&&$.DEBUG&&p>15&&(e>c||e!==o(e)))throw Error(i+g.s*e);if((l=l-f-1)>k)g.c=g.e=null;else if(l<U)g.c=[g.e=0];else{if(g.e=l,g.c=[],f=(l+1)%u,l<0&&(f+=u),f<p){for(f&&g.c.push(+h.slice(0,f)),p-=u;f<p;)g.c.push(+h.slice(f,f+=u));f=u-(h=h.slice(f)).length}else f-=p;for(;f--;h+="0");g.c.push(+h)}}else g.c=[g.e=0]}function q(e,t,r,n){var o,s,i,a,u;if(null==r?r=P:m(r,0,8),!e.c)return e.toString();if(o=e.c[0],i=e.e,null==t)u=h(e.c),u=1==n||2==n&&(i<=_||i>=F)?A(u,i):w(u,i,"0");else if(s=(e=K(new $(e),t,r)).e,a=(u=h(e.c)).length,1==n||2==n&&(t<=s||s<=_)){for(;a<t;u+="0",a++);u=A(u,s)}else if(t-=i+(2===n&&s>i),u=w(u,s,"0"),s+1>a){if(--t>0)for(u+=".";t--;u+="0");}else if((t+=s-a)>0)for(s+1==a&&(u+=".");t--;u+="0");return e.s<0&&o?"-"+u:u}function Y(e,t){for(var r,n,o=1,s=new $(e[0]);o<e.length;o++)(!(n=new $(e[o])).s||(r=g(s,n))===t||0===r&&s.s===t)&&(s=n);return s}function j(e,t,r){for(var n=1,o=t.length;!t[--o];t.pop());for(o=t[0];o>=10;o/=10,n++);return(r=n+r*u-1)>k?e.c=e.e=null:r<U?e.c=[e.e=0]:(e.e=r,e.c=t),e}function K(e,t,r,s){var i,c,f,d,p,h,g,m=e.c,E=l;if(m){e:{for(i=1,d=m[0];d>=10;d/=10,i++);if((c=t-i)<0)c+=u,f=t,p=m[h=0],g=o(p/E[i-f-1]%10);else if((h=n((c+1)/u))>=m.length){if(!s)break e;for(;m.length<=h;m.push(0));p=g=0,i=1,f=(c%=u)-u+1}else{for(p=d=m[h],i=1;d>=10;d/=10,i++);g=(f=(c%=u)-u+i)<0?0:o(p/E[i-f-1]%10)}if(s=s||t<0||null!=m[h+1]||(f<0?p:p%E[i-f-1]),s=r<4?(g||s)&&(0==r||r==(e.s<0?3:2)):g>5||5==g&&(4==r||s||6==r&&(c>0?f>0?p/E[i-f]:0:m[h-1])%10&1||r==(e.s<0?8:7)),t<1||!m[0])return m.length=0,s?(t-=e.e+1,m[0]=E[(u-t%u)%u],e.e=-t||0):m[0]=e.e=0,e;if(0==c?(m.length=h,d=1,h--):(m.length=h+1,d=E[u-c],m[h]=f>0?o(p/E[i-f]%E[f])*d:0),s)for(;;){if(0==h){for(c=1,f=m[0];f>=10;f/=10,c++);for(f=m[0]+=d,d=1;f>=10;f/=10,d++);c!=d&&(e.e++,m[0]==a&&(m[0]=1));break}if(m[h]+=d,m[h]!=a)break;m[h--]=0,d=1}for(c=m.length;0===m[--c];m.pop());}e.e>k?e.c=e.e=null:e.e<U&&(e.c=[e.e=0])}return e}function W(e){var t,r=e.e;return null===r?e.toString():(t=h(e.c),t=r<=_||r>=F?A(t,r):w(t,r,"0"),e.s<0?"-"+t:t)}return $.clone=e,$.ROUND_UP=0,$.ROUND_DOWN=1,$.ROUND_CEIL=2,$.ROUND_FLOOR=3,$.ROUND_HALF_UP=4,$.ROUND_HALF_DOWN=5,$.ROUND_HALF_EVEN=6,$.ROUND_HALF_CEIL=7,$.ROUND_HALF_FLOOR=8,$.EUCLID=9,$.config=$.set=function(e){var t,r;if(null!=e){if("object"!=typeof e)throw Error(s+"Object expected: "+e);if(e.hasOwnProperty(t="DECIMAL_PLACES")&&(m(r=e[t],0,d,t),B=r),e.hasOwnProperty(t="ROUNDING_MODE")&&(m(r=e[t],0,8,t),P=r),e.hasOwnProperty(t="EXPONENTIAL_AT")&&((r=e[t])&&r.pop?(m(r[0],-d,0,t),m(r[1],0,d,t),_=r[0],F=r[1]):(m(r,-d,d,t),_=-(F=r<0?-r:r))),e.hasOwnProperty(t="RANGE"))if((r=e[t])&&r.pop)m(r[0],-d,-1,t),m(r[1],1,d,t),U=r[0],k=r[1];else{if(m(r,-d,d,t),!r)throw Error(s+t+" cannot be zero: "+r);U=-(k=r<0?-r:r)}if(e.hasOwnProperty(t="CRYPTO")){if((r=e[t])!==!!r)throw Error(s+t+" not true or false: "+r);if(r){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw L=!r,Error(s+"crypto unavailable");L=r}else L=r}if(e.hasOwnProperty(t="MODULO_MODE")&&(m(r=e[t],0,9,t),M=r),e.hasOwnProperty(t="POW_PRECISION")&&(m(r=e[t],0,d,t),V=r),e.hasOwnProperty(t="FORMAT")){if("object"!=typeof(r=e[t]))throw Error(s+t+" not an object: "+r);z=r}if(e.hasOwnProperty(t="ALPHABET")){if("string"!=typeof(r=e[t])||/^.?$|[+\-.\s]|(.).*\1/.test(r))throw Error(s+t+" invalid: "+r);G="0123456789"==r.slice(0,10),Q=r}}return{DECIMAL_PLACES:B,ROUNDING_MODE:P,EXPONENTIAL_AT:[_,F],RANGE:[U,k],CRYPTO:L,MODULO_MODE:M,POW_PRECISION:V,FORMAT:z,ALPHABET:Q}},$.isBigNumber=function(e){if(!e||!0!==e._isBigNumber)return!1;if(!$.DEBUG)return!0;var t,r,n=e.c,i=e.e,c=e.s;e:if("[object Array]"=={}.toString.call(n)){if((1===c||-1===c)&&i>=-d&&i<=d&&i===o(i)){if(0===n[0]){if(0===i&&1===n.length)return!0;break e}if((t=(i+1)%u)<1&&(t+=u),String(n[0]).length==t){for(t=0;t<n.length;t++)if((r=n[t])<0||r>=a||r!==o(r))break e;if(0!==r)return!0}}}else if(null===n&&null===i&&(null===c||1===c||-1===c))return!0;throw Error(s+"Invalid BigNumber: "+e)},$.maximum=$.max=function(){return Y(arguments,-1)},$.minimum=$.min=function(){return Y(arguments,1)},$.random=(O=9007199254740992,I=Math.random()*O&2097151?function(){return o(Math.random()*O)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(e){var t,r,i,a,c,f=0,p=[],h=new $(R);if(null==e?e=B:m(e,0,d),a=n(e/u),L)if(crypto.getRandomValues){for(t=crypto.getRandomValues(new Uint32Array(a*=2));f<a;)(c=131072*t[f]+(t[f+1]>>>11))>=9e15?(r=crypto.getRandomValues(new Uint32Array(2)),t[f]=r[0],t[f+1]=r[1]):(p.push(c%1e14),f+=2);f=a/2}else{if(!crypto.randomBytes)throw L=!1,Error(s+"crypto unavailable");for(t=crypto.randomBytes(a*=7);f<a;)(c=281474976710656*(31&t[f])+1099511627776*t[f+1]+4294967296*t[f+2]+16777216*t[f+3]+(t[f+4]<<16)+(t[f+5]<<8)+t[f+6])>=9e15?crypto.randomBytes(7).copy(t,f):(p.push(c%1e14),f+=7);f=a/7}if(!L)for(;f<a;)(c=I())<9e15&&(p[f++]=c%1e14);for(a=p[--f],e%=u,a&&e&&(c=l[u-e],p[f]=o(a/c)*c);0===p[f];p.pop(),f--);if(f<0)p=[i=0];else{for(i=-1;0===p[0];p.splice(0,1),i-=u);for(f=1,c=p[0];c>=10;c/=10,f++);f<u&&(i-=u-f)}return h.e=i,h.c=p,h}),$.sum=function(){for(var e=1,t=arguments,r=new $(t[0]);e<t.length;)r=r.plus(t[e++]);return r},C=function(){var e="0123456789";function t(e,t,r,n){for(var o,s,i=[0],a=0,u=e.length;a<u;){for(s=i.length;s--;i[s]*=t);for(i[0]+=n.indexOf(e.charAt(a++)),o=0;o<i.length;o++)i[o]>r-1&&(null==i[o+1]&&(i[o+1]=0),i[o+1]+=i[o]/r|0,i[o]%=r)}return i.reverse()}return function(r,n,o,s,i){var a,u,c,l,f,d,p,g,m=r.indexOf("."),E=B,A=P;for(m>=0&&(l=V,V=0,r=r.replace(".",""),d=(g=new $(n)).pow(r.length-m),V=l,g.c=t(w(h(d.c),d.e,"0"),10,o,e),g.e=g.c.length),c=l=(p=t(r,n,o,i?(a=Q,e):(a=e,Q))).length;0==p[--l];p.pop());if(!p[0])return a.charAt(0);if(m<0?--c:(d.c=p,d.e=c,d.s=s,p=(d=y(d,g,E,A,o)).c,f=d.r,c=d.e),m=p[u=c+E+1],l=o/2,f=f||u<0||null!=p[u+1],f=A<4?(null!=m||f)&&(0==A||A==(d.s<0?3:2)):m>l||m==l&&(4==A||f||6==A&&1&p[u-1]||A==(d.s<0?8:7)),u<1||!p[0])r=f?w(a.charAt(1),-E,a.charAt(0)):a.charAt(0);else{if(p.length=u,f)for(--o;++p[--u]>o;)p[u]=0,u||(++c,p=[1].concat(p));for(l=p.length;!p[--l];);for(m=0,r="";m<=l;r+=a.charAt(p[m++]));r=w(r,c,a.charAt(0))}return r}}(),y=function(){function e(e,t,r){var n,o,s,i,a=0,u=e.length,c=t%f,l=t/f|0;for(e=e.slice();u--;)a=((o=c*(s=e[u]%f)+(n=l*s+(i=e[u]/f|0)*c)%f*f+a)/r|0)+(n/f|0)+l*i,e[u]=o%r;return a&&(e=[a].concat(e)),e}function t(e,t,r,n){var o,s;if(r!=n)s=r>n?1:-1;else for(o=s=0;o<r;o++)if(e[o]!=t[o]){s=e[o]>t[o]?1:-1;break}return s}function r(e,t,r,n){for(var o=0;r--;)e[r]-=o,o=e[r]<t[r]?1:0,e[r]=o*n+e[r]-t[r];for(;!e[0]&&e.length>1;e.splice(0,1));}return function(n,s,i,c,l){var f,d,h,g,m,E,A,w,y,C,b,O,I,x,T,N,D,v=n.s==s.s?1:-1,S=n.c,R=s.c;if(!(S&&S[0]&&R&&R[0]))return new $(n.s&&s.s&&(S?!R||S[0]!=R[0]:R)?S&&0==S[0]||!R?0*v:v/0:NaN);for(y=(w=new $(v)).c=[],v=i+(d=n.e-s.e)+1,l||(l=a,d=p(n.e/u)-p(s.e/u),v=v/u|0),h=0;R[h]==(S[h]||0);h++);if(R[h]>(S[h]||0)&&d--,v<0)y.push(1),g=!0;else{for(x=S.length,N=R.length,h=0,v+=2,(m=o(l/(R[0]+1)))>1&&(R=e(R,m,l),S=e(S,m,l),N=R.length,x=S.length),I=N,b=(C=S.slice(0,N)).length;b<N;C[b++]=0);D=R.slice(),D=[0].concat(D),T=R[0],R[1]>=l/2&&T++;do{if(m=0,(f=t(R,C,N,b))<0){if(O=C[0],N!=b&&(O=O*l+(C[1]||0)),(m=o(O/T))>1)for(m>=l&&(m=l-1),A=(E=e(R,m,l)).length,b=C.length;1==t(E,C,A,b);)m--,r(E,N<A?D:R,A,l),A=E.length,f=1;else 0==m&&(f=m=1),A=(E=R.slice()).length;if(A<b&&(E=[0].concat(E)),r(C,E,b,l),b=C.length,-1==f)for(;t(R,C,N,b)<1;)m++,r(C,N<b?D:R,b,l),b=C.length}else 0===f&&(m++,C=[0]);y[h++]=m,C[0]?C[b++]=S[I]||0:(C=[S[I]],b=1)}while((I++<x||null!=C[0])&&v--);g=null!=C[0],y[0]||y.splice(0,1)}if(l==a){for(h=1,v=y[0];v>=10;v/=10,h++);K(w,i+(w.e=h+d*u-1)+1,c,g)}else w.e=d,w.r=+g;return w}}(),x=/^(-?)0([xbo])(?=\w[\w.]*$)/i,T=/^([^.]+)\.$/,N=/^\.([^.]+)$/,D=/^-?(Infinity|NaN)$/,v=/^\s*\+(?=[\w.])|^\s+|\s+$/g,b=function(e,t,r,n){var o,i=r?t:t.replace(v,"");if(D.test(i))e.s=isNaN(i)?null:i<0?-1:1;else{if(!r&&(i=i.replace(x,function(e,t,r){return o="x"==(r=r.toLowerCase())?16:"b"==r?2:8,n&&n!=o?e:t}),n&&(o=n,i=i.replace(T,"$1").replace(N,"0.$1")),t!=i))return new $(i,o);if($.DEBUG)throw Error(s+"Not a"+(n?" base "+n:"")+" number: "+t);e.s=null}e.c=e.e=null},S.absoluteValue=S.abs=function(){var e=new $(this);return e.s<0&&(e.s=1),e},S.comparedTo=function(e,t){return g(this,new $(e,t))},S.decimalPlaces=S.dp=function(e,t){var r,n,o,s=this;if(null!=e)return m(e,0,d),null==t?t=P:m(t,0,8),K(new $(s),e+s.e+1,t);if(!(r=s.c))return null;if(n=((o=r.length-1)-p(this.e/u))*u,o=r[o])for(;o%10==0;o/=10,n--);return n<0&&(n=0),n},S.dividedBy=S.div=function(e,t){return y(this,new $(e,t),B,P)},S.dividedToIntegerBy=S.idiv=function(e,t){return y(this,new $(e,t),0,1)},S.exponentiatedBy=S.pow=function(e,t){var r,i,a,c,l,f,d,p,h=this;if((e=new $(e)).c&&!e.isInteger())throw Error(s+"Exponent not an integer: "+W(e));if(null!=t&&(t=new $(t)),l=e.e>14,!h.c||!h.c[0]||1==h.c[0]&&!h.e&&1==h.c.length||!e.c||!e.c[0])return p=new $(Math.pow(+W(h),l?e.s*(2-E(e)):+W(e))),t?p.mod(t):p;if(f=e.s<0,t){if(t.c?!t.c[0]:!t.s)return new $(NaN);(i=!f&&h.isInteger()&&t.isInteger())&&(h=h.mod(t))}else{if(e.e>9&&(h.e>0||h.e<-1||(0==h.e?h.c[0]>1||l&&h.c[1]>=24e7:h.c[0]<8e13||l&&h.c[0]<=9999975e7)))return c=h.s<0&&E(e)?-0:0,h.e>-1&&(c=1/c),new $(f?1/c:c);V&&(c=n(V/u+2))}for(l?(r=new $(.5),f&&(e.s=1),d=E(e)):d=(a=Math.abs(+W(e)))%2,p=new $(R);;){if(d){if(!(p=p.times(h)).c)break;c?p.c.length>c&&(p.c.length=c):i&&(p=p.mod(t))}if(a){if(0===(a=o(a/2)))break;d=a%2}else if(K(e=e.times(r),e.e+1,1),e.e>14)d=E(e);else{if(0===(a=+W(e)))break;d=a%2}h=h.times(h),c?h.c&&h.c.length>c&&(h.c.length=c):i&&(h=h.mod(t))}return i?p:(f&&(p=R.div(p)),t?p.mod(t):c?K(p,V,P,undefined):p)},S.integerValue=function(e){var t=new $(this);return null==e?e=P:m(e,0,8),K(t,t.e+1,e)},S.isEqualTo=S.eq=function(e,t){return 0===g(this,new $(e,t))},S.isFinite=function(){return!!this.c},S.isGreaterThan=S.gt=function(e,t){return g(this,new $(e,t))>0},S.isGreaterThanOrEqualTo=S.gte=function(e,t){return 1===(t=g(this,new $(e,t)))||0===t},S.isInteger=function(){return!!this.c&&p(this.e/u)>this.c.length-2},S.isLessThan=S.lt=function(e,t){return g(this,new $(e,t))<0},S.isLessThanOrEqualTo=S.lte=function(e,t){return-1===(t=g(this,new $(e,t)))||0===t},S.isNaN=function(){return!this.s},S.isNegative=function(){return this.s<0},S.isPositive=function(){return this.s>0},S.isZero=function(){return!!this.c&&0==this.c[0]},S.minus=function(e,t){var r,n,o,s,i=this,c=i.s;if(t=(e=new $(e,t)).s,!c||!t)return new $(NaN);if(c!=t)return e.s=-t,i.plus(e);var l=i.e/u,f=e.e/u,d=i.c,h=e.c;if(!l||!f){if(!d||!h)return d?(e.s=-t,e):new $(h?i:NaN);if(!d[0]||!h[0])return h[0]?(e.s=-t,e):new $(d[0]?i:3==P?-0:0)}if(l=p(l),f=p(f),d=d.slice(),c=l-f){for((s=c<0)?(c=-c,o=d):(f=l,o=h),o.reverse(),t=c;t--;o.push(0));o.reverse()}else for(n=(s=(c=d.length)<(t=h.length))?c:t,c=t=0;t<n;t++)if(d[t]!=h[t]){s=d[t]<h[t];break}if(s&&(o=d,d=h,h=o,e.s=-e.s),(t=(n=h.length)-(r=d.length))>0)for(;t--;d[r++]=0);for(t=a-1;n>c;){if(d[--n]<h[n]){for(r=n;r&&!d[--r];d[r]=t);--d[r],d[n]+=a}d[n]-=h[n]}for(;0==d[0];d.splice(0,1),--f);return d[0]?j(e,d,f):(e.s=3==P?-1:1,e.c=[e.e=0],e)},S.modulo=S.mod=function(e,t){var r,n,o=this;return e=new $(e,t),!o.c||!e.s||e.c&&!e.c[0]?new $(NaN):!e.c||o.c&&!o.c[0]?new $(o):(9==M?(n=e.s,e.s=1,r=y(o,e,0,3),e.s=n,r.s*=n):r=y(o,e,0,M),(e=o.minus(r.times(e))).c[0]||1!=M||(e.s=o.s),e)},S.multipliedBy=S.times=function(e,t){var r,n,o,s,i,c,l,d,h,g,m,E,A,w,y,C=this,b=C.c,O=(e=new $(e,t)).c;if(!(b&&O&&b[0]&&O[0]))return!C.s||!e.s||b&&!b[0]&&!O||O&&!O[0]&&!b?e.c=e.e=e.s=null:(e.s*=C.s,b&&O?(e.c=[0],e.e=0):e.c=e.e=null),e;for(n=p(C.e/u)+p(e.e/u),e.s*=C.s,(l=b.length)<(g=O.length)&&(A=b,b=O,O=A,o=l,l=g,g=o),o=l+g,A=[];o--;A.push(0));for(w=a,y=f,o=g;--o>=0;){for(r=0,m=O[o]%y,E=O[o]/y|0,s=o+(i=l);s>o;)r=((d=m*(d=b[--i]%y)+(c=E*d+(h=b[i]/y|0)*m)%y*y+A[s]+r)/w|0)+(c/y|0)+E*h,A[s--]=d%w;A[s]=r}return r?++n:A.splice(0,1),j(e,A,n)},S.negated=function(){var e=new $(this);return e.s=-e.s||null,e},S.plus=function(e,t){var r,n=this,o=n.s;if(t=(e=new $(e,t)).s,!o||!t)return new $(NaN);if(o!=t)return e.s=-t,n.minus(e);var s=n.e/u,i=e.e/u,c=n.c,l=e.c;if(!s||!i){if(!c||!l)return new $(o/0);if(!c[0]||!l[0])return l[0]?e:new $(c[0]?n:0*o)}if(s=p(s),i=p(i),c=c.slice(),o=s-i){for(o>0?(i=s,r=l):(o=-o,r=c),r.reverse();o--;r.push(0));r.reverse()}for((o=c.length)-(t=l.length)<0&&(r=l,l=c,c=r,t=o),o=0;t;)o=(c[--t]=c[t]+l[t]+o)/a|0,c[t]=a===c[t]?0:c[t]%a;return o&&(c=[o].concat(c),++i),j(e,c,i)},S.precision=S.sd=function(e,t){var r,n,o,s=this;if(null!=e&&e!==!!e)return m(e,1,d),null==t?t=P:m(t,0,8),K(new $(s),e,t);if(!(r=s.c))return null;if(n=(o=r.length-1)*u+1,o=r[o]){for(;o%10==0;o/=10,n--);for(o=r[0];o>=10;o/=10,n++);}return e&&s.e+1>n&&(n=s.e+1),n},S.shiftedBy=function(e){return m(e,-9007199254740991,c),this.times("1e"+e)},S.squareRoot=S.sqrt=function(){var e,t,r,n,o,s=this,i=s.c,a=s.s,u=s.e,c=B+4,l=new $("0.5");if(1!==a||!i||!i[0])return new $(!a||a<0&&(!i||i[0])?NaN:i?s:1/0);if(0==(a=Math.sqrt(+W(s)))||a==1/0?(((t=h(i)).length+u)%2==0&&(t+="0"),a=Math.sqrt(+t),u=p((u+1)/2)-(u<0||u%2),r=new $(t=a==1/0?"5e"+u:(t=a.toExponential()).slice(0,t.indexOf("e")+1)+u)):r=new $(a+""),r.c[0])for((a=(u=r.e)+c)<3&&(a=0);;)if(o=r,r=l.times(o.plus(y(s,o,c,1))),h(o.c).slice(0,a)===(t=h(r.c)).slice(0,a)){if(r.e<u&&--a,"9999"!=(t=t.slice(a-3,a+1))&&(n||"4999"!=t)){+t&&(+t.slice(1)||"5"!=t.charAt(0))||(K(r,r.e+B+2,1),e=!r.times(r).eq(s));break}if(!n&&(K(o,o.e+B+2,0),o.times(o).eq(s))){r=o;break}c+=4,a+=4,n=1}return K(r,r.e+B+1,P,e)},S.toExponential=function(e,t){return null!=e&&(m(e,0,d),e++),q(this,e,t,1)},S.toFixed=function(e,t){return null!=e&&(m(e,0,d),e=e+this.e+1),q(this,e,t)},S.toFormat=function(e,t,r){var n,o=this;if(null==r)null!=e&&t&&"object"==typeof t?(r=t,t=null):e&&"object"==typeof e?(r=e,e=t=null):r=z;else if("object"!=typeof r)throw Error(s+"Argument not an object: "+r);if(n=o.toFixed(e,t),o.c){var i,a=n.split("."),u=+r.groupSize,c=+r.secondaryGroupSize,l=r.groupSeparator||"",f=a[0],d=a[1],p=o.s<0,h=p?f.slice(1):f,g=h.length;if(c&&(i=u,u=c,c=i,g-=i),u>0&&g>0){for(i=g%u||u,f=h.substr(0,i);i<g;i+=u)f+=l+h.substr(i,u);c>0&&(f+=l+h.slice(i)),p&&(f="-"+f)}n=d?f+(r.decimalSeparator||"")+((c=+r.fractionGroupSize)?d.replace(new RegExp("\\d{"+c+"}\\B","g"),"$&"+(r.fractionGroupSeparator||"")):d):f}return(r.prefix||"")+n+(r.suffix||"")},S.toFraction=function(e){var t,r,n,o,i,a,c,f,d,p,g,m,E=this,A=E.c;if(null!=e&&(!(c=new $(e)).isInteger()&&(c.c||1!==c.s)||c.lt(R)))throw Error(s+"Argument "+(c.isInteger()?"out of range: ":"not an integer: ")+W(c));if(!A)return new $(E);for(t=new $(R),d=r=new $(R),n=f=new $(R),m=h(A),i=t.e=m.length-E.e-1,t.c[0]=l[(a=i%u)<0?u+a:a],e=!e||c.comparedTo(t)>0?i>0?t:d:c,a=k,k=1/0,c=new $(m),f.c[0]=0;p=y(c,t,0,1),1!=(o=r.plus(p.times(n))).comparedTo(e);)r=n,n=o,d=f.plus(p.times(o=d)),f=o,t=c.minus(p.times(o=t)),c=o;return o=y(e.minus(r),n,0,1),f=f.plus(o.times(d)),r=r.plus(o.times(n)),f.s=d.s=E.s,g=y(d,n,i*=2,P).minus(E).abs().comparedTo(y(f,r,i,P).minus(E).abs())<1?[d,n]:[f,r],k=a,g},S.toNumber=function(){return+W(this)},S.toPrecision=function(e,t){return null!=e&&m(e,1,d),q(this,e,t,2)},S.toString=function(e){var t,r=this,n=r.s,o=r.e;return null===o?n?(t="Infinity",n<0&&(t="-"+t)):t="NaN":(null==e?t=o<=_||o>=F?A(h(r.c),o):w(h(r.c),o,"0"):10===e&&G?t=w(h((r=K(new $(r),B+o+1,P)).c),r.e,"0"):(m(e,2,Q.length,"Base"),t=C(w(h(r.c),o,"0"),10,e,n,!0)),n<0&&r.c[0]&&(t="-"+t)),t},S.valueOf=S.toJSON=function(){return W(this)},S._isBigNumber=!0,S[Symbol.toStringTag]="BigNumber",S[Symbol.for("nodejs.util.inspect.custom")]=S.valueOf,null!=t&&$.set(t),$}();class C extends Error{constructor(e){super(e.message),this.name="SwapError",this.code=e.code,this.details=e.details,Error.captureStackTrace&&Error.captureStackTrace(this,C)}}const b={V2:0,V3:1},O="0x0000000000000000000000000000000000000001",I="0x0000000000000000000000000000000000000000",x=5,T="https://api-public.bitzy.app",N={3637:{BITZY_V3:"0xA5E0AE4e5103dc71cA290AA3654830442357A489",BITZY_V2:"0x07c49Ade88b40f1Ac05707f236d7706f834F6BDB",AVOCADO_V2:"0xA4B4cDeC4fE2839d3D3a49Ad5E20c21c01A31091"},3636:{BITZY_V3:"0xA5E0AE4e5103dc71cA290AA3654830442357A489",BITZY_V2:"0x07c49Ade88b40f1Ac05707f236d7706f834F6BDB",AVOCADO_V2:"0xA4B4cDeC4fE2839d3D3a49Ad5E20c21c01A31091"}},D={3637:{factoryAddress:"0xDF2CA43f59fd92874e6C1ef887f7E14cb1f354dD",v3FactoryAddress:"0xa8C00286d8d37131c1d033dEeE2F754148932800",v3PositionManagerAddress:"0x76F3e7e326479Ef559996Cf5ab0aCB79Be4626FD",v3WalletHelperAddress:"0xd9Db96Aa882Da764feFff3eE427701B0337e8Ae7",routerAddress:"0x41207Eadf1932966Ff75bdc35e55D2C6734E47D4",aggregatorAddress:"0x5a0690AC82AAAA2e25bC130E900CD31eE9B67DB8",otcAddress:"0xe97ED77EB36A09c37B57D69A5000d8831167A854",memeTokenGenerator:"0x1cb880329265c7A5deDaD6301b1fbd2684CDd200",bitzyQueryAddress:"0x5b5079587501Bd85d3CDf5bFDf299f4eaAe98c23",wrappedAddress:"0x0D2437F93Fed6EA64Ef01cCde385FB1263910C56",nativeAddress:"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",gasLimit:BigInt(5e10)},3636:{factoryAddress:"0x472F9A40F47e0e0F770b224AeC2DD093cf5783aC",v3FactoryAddress:"0xc89e6aD4aD42Eeb82dfBA4c301CDaEDfd794A778",v3PositionManagerAddress:"0xA05E35Fa8997852E6a4A073461E36db1AA725D39",v3WalletHelperAddress:"0x232182B50E1d3c037b3E0bdbd89226d7730cFe0e",routerAddress:"0x07c49Ade88b40f1Ac05707f236d7706f834F6BDB",aggregatorAddress:"0x33B1Ed34c11910F767B15eBAbAB782D61FB2C5Ea",otcAddress:"0xB582f4B568f13F29Bba7696Fc352E293952D4b7E",memeTokenGenerator:"0xc76b4a09BecA8b34D94dE8BA27AeeF652FA3D2fC",bitzyQueryAddress:"0x2ad4b8912fb4Fe93f79BbCb3Aa6B8C39025FdfCC",wrappedAddress:"0x233631132FD56c8f86D1FC97F0b82420a8d20af3",nativeAddress:"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",gasLimit:BigInt(5e10)}},v={3637:{types:[1,2],enabledSources:[1]},3636:{types:[1,2],enabledSources:[1]}},S=e=>v[e]||{types:[1,2],enabledSources:[1]},R=e=>D[e],B=D,P=N[3637]||{},_={PATH_V3:"/api/sdk/bestpath/split",ASSET_MINIMUM:"/api/sdk/asset/minimum"},F={INVALID_TOKENS:"INVALID_TOKENS",INVALID_AMOUNT:"INVALID_AMOUNT",NETWORK_NOT_SUPPORTED:"NETWORK_NOT_SUPPORTED",API_ERROR:"API_ERROR",QUERY_ERROR:"QUERY_ERROR",INSUFFICIENT_LIQUIDITY:"INSUFFICIENT_LIQUIDITY"};class U{constructor(e){this.config=e}static getInstance(e){if(!U.instance){console.log(3232,process.env.NEXT_PUBLIC_BITZY_API_KEY);const t={...e,headers:{...process.env.NEXT_PUBLIC_BITZY_API_KEY&&{"authen-key":process.env.NEXT_PUBLIC_BITZY_API_KEY},...e.headers}};U.instance=new U(t)}return U.instance}static resetInstance(){U.instance=null}async request(e,t={}){const r=new AbortController,n=setTimeout(()=>r.abort(),this.config.timeout);try{const o=await fetch(`${this.config.baseUrl}${e}`,{...t,signal:r.signal,headers:{"Content-Type":"application/json",...this.config.headers,...t.headers}});if(clearTimeout(n),!o.ok)throw new Error(`HTTP ${o.status}: ${o.statusText}`);return await o.json()}catch(t){if(clearTimeout(n),t instanceof Error){if("AbortError"===t.name)throw new C({message:"Request timeout",code:F.API_ERROR,details:{endpoint:e,timeout:this.config.timeout}});throw new C({message:t.message,code:F.API_ERROR,details:{endpoint:e,originalError:t}})}throw new C({message:"Unknown API error",code:F.API_ERROR,details:{endpoint:e,originalError:t}})}}async getPathV3(e,t,r,n,o){const s={src:e.address,dest:t.address,amount:r,typeId:n,sourceId:o},i=this.buildQueryString(s);return this.request(`${_.PATH_V3}?${i}`,{method:"GET"})}async getAssetMinimum(){return this.request(_.ASSET_MINIMUM,{method:"GET"})}buildQueryString(e){return Object.keys(e).reduce((t,r)=>[...t,`${r}=${Array.isArray(e[r])?'["'+e[r].map(e=>e).join('","')+'"]':e[r]}`],[]).join("&")}}U.instance=null;let k=null;const L={3637:["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE","0x0D2437F93Fed6EA64Ef01cCde385FB1263910C56","0x29eE6138DD4C9815f46D34a4A1ed48F46758A402","0x9BC574a6f1170e90D80826D86a6126d59198A3Ef","0xA0b86a33E6441b8c4C8C0C4C0C4C0C4C0C4C0C4C","0xdAC17F958D2ee523a2206206994597C13D831ec7"],3636:["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE","0x233631132FD56c8f86D1FC97F0b82420a8d20af3","0xA0b86a33E6441b8c4C8C0C4C0C4C0C4C0C4C0C4C","0xdAC17F958D2ee523a2206206994597C13D831ec7"]};function M(e,t){if(!e?.address)return!1;const r=L[t];return!!r&&r.some(t=>t.toLowerCase()===e.address.toLowerCase())}function V(e,t,r,n=5){const o=M(e,r),s=M(t,r);return o&&s?n:1}async function z(e,t,r,n,o,s,i=5){try{console.log("Fetching online partCount data...");const a=await async function(e,t){const r=Date.now();if(k&&r<k.expiresAt)return console.log("Using cached minimum amounts data"),k.data;console.log("Fetching fresh minimum amounts data from API");const n=U.getInstance({baseUrl:e,timeout:5e3,headers:{...t&&{"authen-key":t}}}),o=await n.getAssetMinimum();if(!o.success)throw new Error(`API request failed: ${o.error||"Unknown error"}`);return k={data:o.data||[],timestamp:r,expiresAt:r+3e5},k.data}(o,s),u=a.find(t=>t.token?.toLowerCase()===e.address.toLowerCase()),c=a.find(e=>e.token?.toLowerCase()===t.address.toLowerCase()),l=new y(r);return u&&c&&l.gte(u.minimumAmount)&&l.gte(c.minimumAmount)?(console.log("Amount meets minimum threshold for both tokens, using partCount = 5"),5):(console.log("Amount below minimum threshold or missing data, falling back to offline logic"),V(e,t,n,i))}catch(r){return console.warn("Failed to fetch online partCount data:",r),console.log("Falling back to offline partCount logic"),V(e,t,n,i)}}async function Q(e,t,r,n,o,s=5,i){try{return await z(e,t,r,n,o,i,s)}catch(e){return console.warn("Online partCount failed, using offline fallback:",e),s}}function G(e,t,r){if(0===t)return 1/0;return e/r/t*100}function $(e,t){return!e||isNaN(Number(e))?new y(0):new y(e).times(new y(10).pow(t))}function q(e,t){return e.address.toLowerCase()===t.toLowerCase()}function Y(e,t){return e.address.toLowerCase()===t.toLowerCase()}function j(e,t){return e&&t&&e.address&&t.address&&e.address!==t.address&&e.chainId===t.chainId}function K(e){if(!e||isNaN(Number(e)))return!1;const t=new y(e);return t.gt(0)&&t.isFinite()}function W(e,t){let r;const n=(...n)=>{clearTimeout(r),r=setTimeout(()=>e(...n),t)};return n.cancel=()=>{clearTimeout(r)},n}const H=[{inputs:[{internalType:"uint256",name:"srcAmount",type:"uint256"},{internalType:"bytes",name:"encodedRoutes",type:"bytes"},{internalType:"uint256",name:"parts",type:"uint256"}],name:"splitQuery",outputs:[{components:[{internalType:"uint256",name:"amountOut",type:"uint256"},{internalType:"uint256",name:"bestIndex",type:"uint256"}],internalType:"struct BitzyQueryV2.OneRoute",name:"",type:"tuple"},{components:[{internalType:"uint256[]",name:"distribution",type:"uint256[]"},{internalType:"uint256",name:"amountOut",type:"uint256"}],internalType:"struct BitzyQueryV2.SplitRoute",name:"",type:"tuple"}],stateMutability:"nonpayable",type:"function"}];class Z{constructor(e){this.config=e}async fetchRoute(t){const{amountIn:r,srcToken:n,dstToken:o,chainId:s,partCount:i,forcePartCount:a}=t,u=a||i||this.getPartCount(n,o,s,this.config.defaultPartCount);if(!j(n,o))throw new C({message:"Invalid tokens provided",code:F.INVALID_TOKENS,details:{srcToken:n,dstToken:o}});if(!K(r))throw new C({message:"Invalid amount provided",code:F.INVALID_AMOUNT,details:{amountIn:r}});const c=$(r,n.decimals),{routerAddress:l,bitzyQueryAddress:f,wrappedAddress:d,nativeAddress:p}=this.config.config,h=q(n,p),g=q(o,p);if(h&&Y(o,d)||g&&Y(n,d)){const t=h?"wrap":"unwrap",r=c;return{routes:[[{routerAddress:l,lpAddress:e.zeroAddress,fromToken:n.address,toToken:o.address,from:n.address,to:o.address,part:"100000000",amountAfterFee:"10000",dexInterface:0}]],distributions:[u],amountOutRoutes:[r],amountOutBN:r,amountInParts:[c],isAmountOutError:!1,isWrap:t}}const m=h?{...n,address:d}:n,E=g?{...o,address:d}:o;try{const r=await this.config.apiClient.getPathV3(m,E,c.toFixed(0),t.types||[1,2],t.enabledSources||[1]),{hops:n,validPath:o}=r.data;if(0===n.length)return console.log("SDK: No hops found"),{routes:[],distributions:[],amountOutRoutes:[],amountOutBN:new y(0),amountInParts:[],isAmountOutError:!0};console.log("SDK: hops.length =",n.length),console.log("SDK: validPath.length =",o.length),console.log("SDK: partCount =",u);const s=e.encodeAbiParameters([{type:"tuple[][]",components:[{type:"address",name:"src"},{type:"address",name:"dest"},{type:"uint8",name:"typeId"},{type:"uint8",name:"sourceId"},{type:"bytes",name:"path"}]}],[n]);let i=new y(0),a=[],l=[];if(this.config.publicClient)try{console.log("SDK: Calling splitQuery with:",{bitzyQueryAddress:f,amountIn:c.toFixed(0),partCount:u,encodedRoutesLength:s.length});const t=e.encodeFunctionData({abi:H,functionName:"splitQuery",args:[c.toFixed(0),s,u]}),r=await this.config.publicClient.call({to:f,data:t,gas:50000000000n,gasPrice:void 0});if(console.log("SDK: Contract call result:",r),r.data){const t=e.decodeFunctionResult({abi:H,functionName:"splitQuery",data:r.data})[1];if(t&&t.amountOut){i=new y(t.amountOut.toString());let r=t.distribution.map(e=>new y(e.toString()).toNumber());l=o.reduce((t,n,o)=>(r[o]>0&&t.push(n.map((t,r,n)=>({routerAddress:P[t.source+"_"+t.type]||e.zeroAddress,lpAddress:t.pool||e.zeroAddress,fromToken:t.src,toToken:t.dest,from:r>0||"V3"===t.type||t.src===d.toLowerCase()?I:O,to:r<n.length-1||r===n.length-1&&t.dest===d.toLowerCase()?I:O,part:"100000000",amountAfterFee:new y(1e4).minus(new y(t.fee||0).dividedBy(100)).toFixed(),dexInterface:b[t.type]||0}))),t),[]),a=r.filter(e=>e>0)}}}catch(e){console.error("SDK: splitQuery contract call failed:",e),i=new y(0),a=[],l=[]}else console.error("SDK: No publicClient available - this is the problem!"),i=new y(0),a=[],l=[];const p=a.map(e=>i.times(e).dividedBy(u).dp(0,y.ROUND_DOWN)),h=a.map(e=>c.times(e).dividedBy(u).dp(0,y.ROUND_DOWN));return{routes:l,distributions:a,amountOutRoutes:p,amountOutBN:i,amountInParts:h,isAmountOutError:!1}}catch(e){throw new C({message:"Failed to fetch swap route",code:F.API_ERROR,details:{originalError:e,options:t}})}}getSupportedNetworks(){return Object.keys(B).map(Number)}getNetworkConfig(e){return this.config.config}getPartCount(e,t,r,n){return V(e,t,r,n)}}async function X(e,t={}){const{apiBaseUrl:r=T,defaultPartCount:n=x,timeout:o=3e4,headers:s={}}=t,i=e.chainId,a=R(i);if(!a)throw new Error(`Unsupported network: ${i}`);const u=U.getInstance({baseUrl:r,timeout:o,headers:s});return new Z({config:{routerAddress:a.routerAddress,bitzyQueryAddress:a.bitzyQueryAddress,wrappedAddress:a.wrappedAddress,nativeAddress:a.nativeAddress},defaultPartCount:n,apiClient:u}).fetchRoute(e)}const J=(r,n,o,s,i={})=>{const a=t.useMemo(()=>({}),[]),u=t.useMemo(()=>({routerAddress:e.zeroAddress,bitzyQueryAddress:e.zeroAddress,wrappedAddress:e.zeroAddress,nativeAddress:e.zeroAddress}),[]),{apiBaseUrl:c,addressConfig:l,defaultPartCount:f,timeout:d,headers:p,refreshInterval:h,publicClient:g,configTypes:m,configEnabledSources:E,forcePartCount:A,useOnlinePartCount:w}=t.useMemo(()=>{const{apiBaseUrl:e=T,config:t=u,defaultPartCount:r=5,timeout:n=3e4,headers:o=a,refreshInterval:s=1e4,publicClient:c,types:l,enabledSources:f,forcePartCount:d,useOnlinePartCount:p=!1}=i;return{apiBaseUrl:e,addressConfig:t,defaultPartCount:r,timeout:n,headers:o,refreshInterval:s,publicClient:c,configTypes:l,configEnabledSources:f,forcePartCount:d,useOnlinePartCount:p}},[i,a,u]),C=t.useMemo(()=>S(s),[s]),b=t.useMemo(()=>m??C.types,[m,C.types]),O=t.useMemo(()=>E??C.enabledSources,[E,C.enabledSources]);t.useEffect(()=>{console.log("config",i)},[i]),t.useEffect(()=>{console.log("srcToken",r)},[r]),t.useEffect(()=>{console.log("dstToken",n)},[n]),t.useEffect(()=>{console.log("amountIn",o)},[o]),t.useEffect(()=>{console.log("chainId",s)},[s]),t.useEffect(()=>{console.log("apiBaseUrl",c)},[c]),t.useEffect(()=>{console.log("addressConfig",l)},[l]),t.useEffect(()=>{console.log("defaultPartCount",f)},[f]),t.useEffect(()=>{console.log("timeout",d)},[d]),t.useEffect(()=>{console.log("headers",p)},[p]),t.useEffect(()=>{console.log("types",b)},[b]),t.useEffect(()=>{console.log("enabledSources",O)},[O]);const[I,x]=t.useState(new y(0)),[N,D]=t.useState([]),[v,B]=t.useState([]),[P,_]=t.useState([]),[F,k]=t.useState([]),[L,M]=t.useState(!1),[z,G]=t.useState(!1),[$,q]=t.useState(),[Y,j]=t.useState(!1),[K,H]=t.useState(null),[X,J]=t.useState(null),ee=t.useMemo(()=>(console.log("partCount",0,w),w?null!==X?X:V(r,n,s,f):(console.log("partCount",1,A),void 0!==A?A:(console.log("partCount",2,f),V(r,n,s,f)))),[f,A,w,X,r,n,s]);t.useEffect(()=>{if(!(w&&r&&n&&o))return void J(null);(async()=>{try{const e=await Q(r,n,o,s,c,f);J(e)}catch(e){console.warn("Failed to fetch online partCount:",e),J(null)}})()},[w,r,n,o,s,c,f]);const te=t.useMemo(()=>{const e=R(s),t=l&&Object.keys(l).length>0?l:{routerAddress:e?.routerAddress||"0x0000000000000000000000000000000000000000",bitzyQueryAddress:e?.bitzyQueryAddress||"0x0000000000000000000000000000000000000000",wrappedAddress:e?.wrappedAddress||"0x0000000000000000000000000000000000000000",nativeAddress:e?.nativeAddress||"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"},r=U.getInstance({baseUrl:c,timeout:d,headers:p});return new Z({config:t,defaultPartCount:f,apiClient:r,publicClient:g})},[l,f,c,d,p,g,s]),re=t.useCallback(()=>{H(null)},[]),ne=t.useCallback(async()=>{if(!r||!n||!o||"0"===o)return x(new y(0)),D([]),B([]),_([]),k([]),G(!1),j(!1),void H(null);M(!0),H(null);try{const e={amountIn:o,srcToken:r,dstToken:n,chainId:s,partCount:ee,types:b,enabledSources:O},t=await te.fetchRoute(e);x(t.amountOutBN),D(t.routes),B(t.distributions),_(t.amountOutRoutes),k(t.amountInParts),G(t.isAmountOutError),q(t.isWrap),j(!0)}catch(e){const t=e instanceof Error?e.message:"Unknown error occurred";H(t),console.error("Error fetching route:",e),x(new y(0)),D([]),B([]),_([]),k([]),G(!0),j(!1)}finally{M(!1)}},[te,r,n,o,s,ee,b,O]),oe=t.useMemo(()=>W(ne,300),[ne]);return t.useEffect(()=>{if(!o||"0"===o)return x(new y(0)),D([]),B([]),_([]),k([]),G(!1),j(!1),void H(null);oe();const e=setInterval(()=>{oe()},h);return()=>{clearInterval(e),"function"==typeof oe.cancel&&oe.cancel()}},[o,r?.address,n?.address,oe,h]),t.useEffect(()=>{Y&&ne()},[ne,Y,te]),{routes:N,distributions:v,amountOutRoutes:P,amountOutBN:I,amountInParts:F,fetchRoute:ne,isLoading:L,isAmountOutError:z,isFirstFetch:Y,isWrap:$,error:K,clearError:re}};exports.APIClient=U,exports.API_ENDPOINTS=_,exports.BITZY_QUERY_ABI=H,exports.CONTRACT_ADDRESSES=D,exports.DEFAULT_NETWORKS=B,exports.DEFAULT_PART_COUNT=x,exports.DEFAULT_TIMEOUT=3e4,exports.DEX_INTERFACE=b,exports.DEX_ROUTER=P,exports.DEX_ROUTERS=N,exports.ERROR_CODES=F,exports.HIGH_VALUE_TOKENS=L,exports.LIQUIDITY_SOURCES=v,exports.ROUTER_TARGET=I,exports.SwapV3Service=Z,exports.USER_TARGET=O,exports.calculatePartCount=function(e,t,r=10){return new y(e).times(t).lt(1)?1:r},exports.calculatePriceImpact=G,exports.clearMinimumAmountsCache=function(){k=null,console.log("Minimum amounts cache cleared")},exports.debounce=W,exports.ensureBigNumber=e=>e instanceof y?e:new y(e),exports.fetchBatchSwapRoutes=async function(e){return(await Promise.allSettled(e.map(async({options:e,config:t})=>{try{return{success:!0,data:await X(e,t)}}catch(e){return{success:!1,error:e instanceof Error?e.message:"Unknown error"}}}))).map(e=>"fulfilled"===e.status?e.value:{success:!1,error:e.reason?.message||"Unknown error"})},exports.fetchSwapRoute=X,exports.fetchSwapRouteSimple=async function(e,t={}){const{types:r,enabledSources:n}=S(e.chainId);return X({...e,types:r,enabledSources:n},{...t,forcePartCount:t.forcePartCount})},exports.formatError=function(e){return"string"==typeof e?e:e?.message?e.message:e?.error?e.error:"Unknown error occurred"},exports.fromTokenAmount=$,exports.getContractAddresses=R,exports.getDexRouters=e=>N[e]||{},exports.getLiquiditySources=S,exports.getOptimalPartCount=function(e,t,r=5){return G(e,t,5)>r?1:5},exports.getPartCountOffline=V,exports.getPartCountOnline=z,exports.getPartCountWithFallback=Q,exports.getSwapQuote=async function(e,t,r,n,o={}){const s=await X({amountIn:r,srcToken:e,dstToken:t,chainId:n},o);return{amountOut:s.amountOutBN.toFixed(0),routes:s.routes.length}},exports.getSwapRoute=X,exports.isBigNumber=e=>e instanceof y,exports.isHighValueToken=M,exports.isNativeToken=q,exports.isWrappedToken=Y,exports.toTokenAmount=function(e,t){return new y(e).dividedBy(new y(10).pow(t)).toString()},exports.useSwapRoutes=J,exports.useSwapV3Routes=J,exports.validateAmount=K,exports.validateTokens=j;
1
+ "use strict";var e=require("react"),t=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,n=Math.ceil,r=Math.floor,s="[BigNumber Error] ",i=s+"Number primitive has more than 15 significant digits: ",o=1e14,a=14,u=9007199254740991,c=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],l=1e7,f=1e9;function d(e){var t=0|e;return e>0||e===t?t:t-1}function h(e){for(var t,n,r=1,s=e.length,i=e[0]+"";r<s;){for(t=e[r++]+"",n=a-t.length;n--;t="0"+t);i+=t}for(s=i.length;48===i.charCodeAt(--s););return i.slice(0,s+1||1)}function p(e,t){var n,r,s=e.c,i=t.c,o=e.s,a=t.s,u=e.e,c=t.e;if(!o||!a)return null;if(n=s&&!s[0],r=i&&!i[0],n||r)return n?r?0:-a:o;if(o!=a)return o;if(n=o<0,r=u==c,!s||!i)return r?0:!s^n?1:-1;if(!r)return u>c^n?1:-1;for(a=(u=s.length)<(c=i.length)?u:c,o=0;o<a;o++)if(s[o]!=i[o])return s[o]>i[o]^n?1:-1;return u==c?0:u>c^n?1:-1}function g(e,t,n,i){if(e<t||e>n||e!==r(e))throw Error(s+(i||"Argument")+("number"==typeof e?e<t||e>n?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function m(e){var t=e.c.length-1;return d(e.e/a)==t&&e.c[t]%2!=0}function y(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function b(e,t,n){var r,s;if(t<0){for(s=n+".";++t;s+=n);e=s+e}else if(++t>(r=e.length)){for(s=n,t-=r;--t;s+=n);e+=s}else t<r&&(e=e.slice(0,t)+"."+e.slice(t));return e}var w=function e(w){var E,A,v,x,I,C,P,O,B,N,S=W.prototype={constructor:W,toString:null,valueOf:null},T=new W(1),$=20,R=4,D=-7,z=21,U=-1e7,L=1e7,_=!1,F=1,k=0,M={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},V="0123456789abcdefghijklmnopqrstuvwxyz",j=!0;function W(e,n){var s,o,c,l,f,d,h,p,m=this;if(!(m instanceof W))return new W(e,n);if(null==n){if(e&&!0===e._isBigNumber)return m.s=e.s,void(!e.c||e.e>L?m.c=m.e=null:e.e<U?m.c=[m.e=0]:(m.e=e.e,m.c=e.c.slice()));if((d="number"==typeof e)&&0*e==0){if(m.s=1/e<0?(e=-e,-1):1,e===~~e){for(l=0,f=e;f>=10;f/=10,l++);return void(l>L?m.c=m.e=null:(m.e=l,m.c=[e]))}p=String(e)}else{if(!t.test(p=String(e)))return v(m,p,d);m.s=45==p.charCodeAt(0)?(p=p.slice(1),-1):1}(l=p.indexOf("."))>-1&&(p=p.replace(".","")),(f=p.search(/e/i))>0?(l<0&&(l=f),l+=+p.slice(f+1),p=p.substring(0,f)):l<0&&(l=p.length)}else{if(g(n,2,V.length,"Base"),10==n&&j)return q(m=new W(e),$+m.e+1,R);if(p=String(e),d="number"==typeof e){if(0*e!=0)return v(m,p,d,n);if(m.s=1/e<0?(p=p.slice(1),-1):1,W.DEBUG&&p.replace(/^0\.0*|\./,"").length>15)throw Error(i+e)}else m.s=45===p.charCodeAt(0)?(p=p.slice(1),-1):1;for(s=V.slice(0,n),l=f=0,h=p.length;f<h;f++)if(s.indexOf(o=p.charAt(f))<0){if("."==o){if(f>l){l=h;continue}}else if(!c&&(p==p.toUpperCase()&&(p=p.toLowerCase())||p==p.toLowerCase()&&(p=p.toUpperCase()))){c=!0,f=-1,l=0;continue}return v(m,String(e),d,n)}d=!1,(l=(p=A(p,n,10,m.s)).indexOf("."))>-1?p=p.replace(".",""):l=p.length}for(f=0;48===p.charCodeAt(f);f++);for(h=p.length;48===p.charCodeAt(--h););if(p=p.slice(f,++h)){if(h-=f,d&&W.DEBUG&&h>15&&(e>u||e!==r(e)))throw Error(i+m.s*e);if((l=l-f-1)>L)m.c=m.e=null;else if(l<U)m.c=[m.e=0];else{if(m.e=l,m.c=[],f=(l+1)%a,l<0&&(f+=a),f<h){for(f&&m.c.push(+p.slice(0,f)),h-=a;f<h;)m.c.push(+p.slice(f,f+=a));f=a-(p=p.slice(f)).length}else f-=h;for(;f--;p+="0");m.c.push(+p)}}else m.c=[m.e=0]}function G(e,t,n,r){var s,i,o,a,u;if(null==n?n=R:g(n,0,8),!e.c)return e.toString();if(s=e.c[0],o=e.e,null==t)u=h(e.c),u=1==r||2==r&&(o<=D||o>=z)?y(u,o):b(u,o,"0");else if(i=(e=q(new W(e),t,n)).e,a=(u=h(e.c)).length,1==r||2==r&&(t<=i||i<=D)){for(;a<t;u+="0",a++);u=y(u,i)}else if(t-=o+(2===r&&i>o),u=b(u,i,"0"),i+1>a){if(--t>0)for(u+=".";t--;u+="0");}else if((t+=i-a)>0)for(i+1==a&&(u+=".");t--;u+="0");return e.s<0&&s?"-"+u:u}function Q(e,t){for(var n,r,s=1,i=new W(e[0]);s<e.length;s++)(!(r=new W(e[s])).s||(n=p(i,r))===t||0===n&&i.s===t)&&(i=r);return i}function Y(e,t,n){for(var r=1,s=t.length;!t[--s];t.pop());for(s=t[0];s>=10;s/=10,r++);return(n=r+n*a-1)>L?e.c=e.e=null:n<U?e.c=[e.e=0]:(e.e=n,e.c=t),e}function q(e,t,s,i){var u,l,f,d,h,p,g,m=e.c,y=c;if(m){e:{for(u=1,d=m[0];d>=10;d/=10,u++);if((l=t-u)<0)l+=a,f=t,h=m[p=0],g=r(h/y[u-f-1]%10);else if((p=n((l+1)/a))>=m.length){if(!i)break e;for(;m.length<=p;m.push(0));h=g=0,u=1,f=(l%=a)-a+1}else{for(h=d=m[p],u=1;d>=10;d/=10,u++);g=(f=(l%=a)-a+u)<0?0:r(h/y[u-f-1]%10)}if(i=i||t<0||null!=m[p+1]||(f<0?h:h%y[u-f-1]),i=s<4?(g||i)&&(0==s||s==(e.s<0?3:2)):g>5||5==g&&(4==s||i||6==s&&(l>0?f>0?h/y[u-f]:0:m[p-1])%10&1||s==(e.s<0?8:7)),t<1||!m[0])return m.length=0,i?(t-=e.e+1,m[0]=y[(a-t%a)%a],e.e=-t||0):m[0]=e.e=0,e;if(0==l?(m.length=p,d=1,p--):(m.length=p+1,d=y[a-l],m[p]=f>0?r(h/y[u-f]%y[f])*d:0),i)for(;;){if(0==p){for(l=1,f=m[0];f>=10;f/=10,l++);for(f=m[0]+=d,d=1;f>=10;f/=10,d++);l!=d&&(e.e++,m[0]==o&&(m[0]=1));break}if(m[p]+=d,m[p]!=o)break;m[p--]=0,d=1}for(l=m.length;0===m[--l];m.pop());}e.e>L?e.c=e.e=null:e.e<U&&(e.c=[e.e=0])}return e}function K(e){var t,n=e.e;return null===n?e.toString():(t=h(e.c),t=n<=D||n>=z?y(t,n):b(t,n,"0"),e.s<0?"-"+t:t)}return W.clone=e,W.ROUND_UP=0,W.ROUND_DOWN=1,W.ROUND_CEIL=2,W.ROUND_FLOOR=3,W.ROUND_HALF_UP=4,W.ROUND_HALF_DOWN=5,W.ROUND_HALF_EVEN=6,W.ROUND_HALF_CEIL=7,W.ROUND_HALF_FLOOR=8,W.EUCLID=9,W.config=W.set=function(e){var t,n;if(null!=e){if("object"!=typeof e)throw Error(s+"Object expected: "+e);if(e.hasOwnProperty(t="DECIMAL_PLACES")&&(g(n=e[t],0,f,t),$=n),e.hasOwnProperty(t="ROUNDING_MODE")&&(g(n=e[t],0,8,t),R=n),e.hasOwnProperty(t="EXPONENTIAL_AT")&&((n=e[t])&&n.pop?(g(n[0],-f,0,t),g(n[1],0,f,t),D=n[0],z=n[1]):(g(n,-f,f,t),D=-(z=n<0?-n:n))),e.hasOwnProperty(t="RANGE"))if((n=e[t])&&n.pop)g(n[0],-f,-1,t),g(n[1],1,f,t),U=n[0],L=n[1];else{if(g(n,-f,f,t),!n)throw Error(s+t+" cannot be zero: "+n);U=-(L=n<0?-n:n)}if(e.hasOwnProperty(t="CRYPTO")){if((n=e[t])!==!!n)throw Error(s+t+" not true or false: "+n);if(n){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw _=!n,Error(s+"crypto unavailable");_=n}else _=n}if(e.hasOwnProperty(t="MODULO_MODE")&&(g(n=e[t],0,9,t),F=n),e.hasOwnProperty(t="POW_PRECISION")&&(g(n=e[t],0,f,t),k=n),e.hasOwnProperty(t="FORMAT")){if("object"!=typeof(n=e[t]))throw Error(s+t+" not an object: "+n);M=n}if(e.hasOwnProperty(t="ALPHABET")){if("string"!=typeof(n=e[t])||/^.?$|[+\-.\s]|(.).*\1/.test(n))throw Error(s+t+" invalid: "+n);j="0123456789"==n.slice(0,10),V=n}}return{DECIMAL_PLACES:$,ROUNDING_MODE:R,EXPONENTIAL_AT:[D,z],RANGE:[U,L],CRYPTO:_,MODULO_MODE:F,POW_PRECISION:k,FORMAT:M,ALPHABET:V}},W.isBigNumber=function(e){if(!e||!0!==e._isBigNumber)return!1;if(!W.DEBUG)return!0;var t,n,i=e.c,u=e.e,c=e.s;e:if("[object Array]"=={}.toString.call(i)){if((1===c||-1===c)&&u>=-f&&u<=f&&u===r(u)){if(0===i[0]){if(0===u&&1===i.length)return!0;break e}if((t=(u+1)%a)<1&&(t+=a),String(i[0]).length==t){for(t=0;t<i.length;t++)if((n=i[t])<0||n>=o||n!==r(n))break e;if(0!==n)return!0}}}else if(null===i&&null===u&&(null===c||1===c||-1===c))return!0;throw Error(s+"Invalid BigNumber: "+e)},W.maximum=W.max=function(){return Q(arguments,-1)},W.minimum=W.min=function(){return Q(arguments,1)},W.random=(x=9007199254740992,I=Math.random()*x&2097151?function(){return r(Math.random()*x)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(e){var t,i,o,u,l,d=0,h=[],p=new W(T);if(null==e?e=$:g(e,0,f),u=n(e/a),_)if(crypto.getRandomValues){for(t=crypto.getRandomValues(new Uint32Array(u*=2));d<u;)(l=131072*t[d]+(t[d+1]>>>11))>=9e15?(i=crypto.getRandomValues(new Uint32Array(2)),t[d]=i[0],t[d+1]=i[1]):(h.push(l%1e14),d+=2);d=u/2}else{if(!crypto.randomBytes)throw _=!1,Error(s+"crypto unavailable");for(t=crypto.randomBytes(u*=7);d<u;)(l=281474976710656*(31&t[d])+1099511627776*t[d+1]+4294967296*t[d+2]+16777216*t[d+3]+(t[d+4]<<16)+(t[d+5]<<8)+t[d+6])>=9e15?crypto.randomBytes(7).copy(t,d):(h.push(l%1e14),d+=7);d=u/7}if(!_)for(;d<u;)(l=I())<9e15&&(h[d++]=l%1e14);for(u=h[--d],e%=a,u&&e&&(l=c[a-e],h[d]=r(u/l)*l);0===h[d];h.pop(),d--);if(d<0)h=[o=0];else{for(o=-1;0===h[0];h.splice(0,1),o-=a);for(d=1,l=h[0];l>=10;l/=10,d++);d<a&&(o-=a-d)}return p.e=o,p.c=h,p}),W.sum=function(){for(var e=1,t=arguments,n=new W(t[0]);e<t.length;)n=n.plus(t[e++]);return n},A=function(){var e="0123456789";function t(e,t,n,r){for(var s,i,o=[0],a=0,u=e.length;a<u;){for(i=o.length;i--;o[i]*=t);for(o[0]+=r.indexOf(e.charAt(a++)),s=0;s<o.length;s++)o[s]>n-1&&(null==o[s+1]&&(o[s+1]=0),o[s+1]+=o[s]/n|0,o[s]%=n)}return o.reverse()}return function(n,r,s,i,o){var a,u,c,l,f,d,p,g,m=n.indexOf("."),y=$,w=R;for(m>=0&&(l=k,k=0,n=n.replace(".",""),d=(g=new W(r)).pow(n.length-m),k=l,g.c=t(b(h(d.c),d.e,"0"),10,s,e),g.e=g.c.length),c=l=(p=t(n,r,s,o?(a=V,e):(a=e,V))).length;0==p[--l];p.pop());if(!p[0])return a.charAt(0);if(m<0?--c:(d.c=p,d.e=c,d.s=i,p=(d=E(d,g,y,w,s)).c,f=d.r,c=d.e),m=p[u=c+y+1],l=s/2,f=f||u<0||null!=p[u+1],f=w<4?(null!=m||f)&&(0==w||w==(d.s<0?3:2)):m>l||m==l&&(4==w||f||6==w&&1&p[u-1]||w==(d.s<0?8:7)),u<1||!p[0])n=f?b(a.charAt(1),-y,a.charAt(0)):a.charAt(0);else{if(p.length=u,f)for(--s;++p[--u]>s;)p[u]=0,u||(++c,p=[1].concat(p));for(l=p.length;!p[--l];);for(m=0,n="";m<=l;n+=a.charAt(p[m++]));n=b(n,c,a.charAt(0))}return n}}(),E=function(){function e(e,t,n){var r,s,i,o,a=0,u=e.length,c=t%l,f=t/l|0;for(e=e.slice();u--;)a=((s=c*(i=e[u]%l)+(r=f*i+(o=e[u]/l|0)*c)%l*l+a)/n|0)+(r/l|0)+f*o,e[u]=s%n;return a&&(e=[a].concat(e)),e}function t(e,t,n,r){var s,i;if(n!=r)i=n>r?1:-1;else for(s=i=0;s<n;s++)if(e[s]!=t[s]){i=e[s]>t[s]?1:-1;break}return i}function n(e,t,n,r){for(var s=0;n--;)e[n]-=s,s=e[n]<t[n]?1:0,e[n]=s*r+e[n]-t[n];for(;!e[0]&&e.length>1;e.splice(0,1));}return function(s,i,u,c,l){var f,h,p,g,m,y,b,w,E,A,v,x,I,C,P,O,B,N=s.s==i.s?1:-1,S=s.c,T=i.c;if(!(S&&S[0]&&T&&T[0]))return new W(s.s&&i.s&&(S?!T||S[0]!=T[0]:T)?S&&0==S[0]||!T?0*N:N/0:NaN);for(E=(w=new W(N)).c=[],N=u+(h=s.e-i.e)+1,l||(l=o,h=d(s.e/a)-d(i.e/a),N=N/a|0),p=0;T[p]==(S[p]||0);p++);if(T[p]>(S[p]||0)&&h--,N<0)E.push(1),g=!0;else{for(C=S.length,O=T.length,p=0,N+=2,(m=r(l/(T[0]+1)))>1&&(T=e(T,m,l),S=e(S,m,l),O=T.length,C=S.length),I=O,v=(A=S.slice(0,O)).length;v<O;A[v++]=0);B=T.slice(),B=[0].concat(B),P=T[0],T[1]>=l/2&&P++;do{if(m=0,(f=t(T,A,O,v))<0){if(x=A[0],O!=v&&(x=x*l+(A[1]||0)),(m=r(x/P))>1)for(m>=l&&(m=l-1),b=(y=e(T,m,l)).length,v=A.length;1==t(y,A,b,v);)m--,n(y,O<b?B:T,b,l),b=y.length,f=1;else 0==m&&(f=m=1),b=(y=T.slice()).length;if(b<v&&(y=[0].concat(y)),n(A,y,v,l),v=A.length,-1==f)for(;t(T,A,O,v)<1;)m++,n(A,O<v?B:T,v,l),v=A.length}else 0===f&&(m++,A=[0]);E[p++]=m,A[0]?A[v++]=S[I]||0:(A=[S[I]],v=1)}while((I++<C||null!=A[0])&&N--);g=null!=A[0],E[0]||E.splice(0,1)}if(l==o){for(p=1,N=E[0];N>=10;N/=10,p++);q(w,u+(w.e=p+h*a-1)+1,c,g)}else w.e=h,w.r=+g;return w}}(),C=/^(-?)0([xbo])(?=\w[\w.]*$)/i,P=/^([^.]+)\.$/,O=/^\.([^.]+)$/,B=/^-?(Infinity|NaN)$/,N=/^\s*\+(?=[\w.])|^\s+|\s+$/g,v=function(e,t,n,r){var i,o=n?t:t.replace(N,"");if(B.test(o))e.s=isNaN(o)?null:o<0?-1:1;else{if(!n&&(o=o.replace(C,function(e,t,n){return i="x"==(n=n.toLowerCase())?16:"b"==n?2:8,r&&r!=i?e:t}),r&&(i=r,o=o.replace(P,"$1").replace(O,"0.$1")),t!=o))return new W(o,i);if(W.DEBUG)throw Error(s+"Not a"+(r?" base "+r:"")+" number: "+t);e.s=null}e.c=e.e=null},S.absoluteValue=S.abs=function(){var e=new W(this);return e.s<0&&(e.s=1),e},S.comparedTo=function(e,t){return p(this,new W(e,t))},S.decimalPlaces=S.dp=function(e,t){var n,r,s,i=this;if(null!=e)return g(e,0,f),null==t?t=R:g(t,0,8),q(new W(i),e+i.e+1,t);if(!(n=i.c))return null;if(r=((s=n.length-1)-d(this.e/a))*a,s=n[s])for(;s%10==0;s/=10,r--);return r<0&&(r=0),r},S.dividedBy=S.div=function(e,t){return E(this,new W(e,t),$,R)},S.dividedToIntegerBy=S.idiv=function(e,t){return E(this,new W(e,t),0,1)},S.exponentiatedBy=S.pow=function(e,t){var i,o,u,c,l,f,d,h,p=this;if((e=new W(e)).c&&!e.isInteger())throw Error(s+"Exponent not an integer: "+K(e));if(null!=t&&(t=new W(t)),l=e.e>14,!p.c||!p.c[0]||1==p.c[0]&&!p.e&&1==p.c.length||!e.c||!e.c[0])return h=new W(Math.pow(+K(p),l?e.s*(2-m(e)):+K(e))),t?h.mod(t):h;if(f=e.s<0,t){if(t.c?!t.c[0]:!t.s)return new W(NaN);(o=!f&&p.isInteger()&&t.isInteger())&&(p=p.mod(t))}else{if(e.e>9&&(p.e>0||p.e<-1||(0==p.e?p.c[0]>1||l&&p.c[1]>=24e7:p.c[0]<8e13||l&&p.c[0]<=9999975e7)))return c=p.s<0&&m(e)?-0:0,p.e>-1&&(c=1/c),new W(f?1/c:c);k&&(c=n(k/a+2))}for(l?(i=new W(.5),f&&(e.s=1),d=m(e)):d=(u=Math.abs(+K(e)))%2,h=new W(T);;){if(d){if(!(h=h.times(p)).c)break;c?h.c.length>c&&(h.c.length=c):o&&(h=h.mod(t))}if(u){if(0===(u=r(u/2)))break;d=u%2}else if(q(e=e.times(i),e.e+1,1),e.e>14)d=m(e);else{if(0===(u=+K(e)))break;d=u%2}p=p.times(p),c?p.c&&p.c.length>c&&(p.c.length=c):o&&(p=p.mod(t))}return o?h:(f&&(h=T.div(h)),t?h.mod(t):c?q(h,k,R,undefined):h)},S.integerValue=function(e){var t=new W(this);return null==e?e=R:g(e,0,8),q(t,t.e+1,e)},S.isEqualTo=S.eq=function(e,t){return 0===p(this,new W(e,t))},S.isFinite=function(){return!!this.c},S.isGreaterThan=S.gt=function(e,t){return p(this,new W(e,t))>0},S.isGreaterThanOrEqualTo=S.gte=function(e,t){return 1===(t=p(this,new W(e,t)))||0===t},S.isInteger=function(){return!!this.c&&d(this.e/a)>this.c.length-2},S.isLessThan=S.lt=function(e,t){return p(this,new W(e,t))<0},S.isLessThanOrEqualTo=S.lte=function(e,t){return-1===(t=p(this,new W(e,t)))||0===t},S.isNaN=function(){return!this.s},S.isNegative=function(){return this.s<0},S.isPositive=function(){return this.s>0},S.isZero=function(){return!!this.c&&0==this.c[0]},S.minus=function(e,t){var n,r,s,i,u=this,c=u.s;if(t=(e=new W(e,t)).s,!c||!t)return new W(NaN);if(c!=t)return e.s=-t,u.plus(e);var l=u.e/a,f=e.e/a,h=u.c,p=e.c;if(!l||!f){if(!h||!p)return h?(e.s=-t,e):new W(p?u:NaN);if(!h[0]||!p[0])return p[0]?(e.s=-t,e):new W(h[0]?u:3==R?-0:0)}if(l=d(l),f=d(f),h=h.slice(),c=l-f){for((i=c<0)?(c=-c,s=h):(f=l,s=p),s.reverse(),t=c;t--;s.push(0));s.reverse()}else for(r=(i=(c=h.length)<(t=p.length))?c:t,c=t=0;t<r;t++)if(h[t]!=p[t]){i=h[t]<p[t];break}if(i&&(s=h,h=p,p=s,e.s=-e.s),(t=(r=p.length)-(n=h.length))>0)for(;t--;h[n++]=0);for(t=o-1;r>c;){if(h[--r]<p[r]){for(n=r;n&&!h[--n];h[n]=t);--h[n],h[r]+=o}h[r]-=p[r]}for(;0==h[0];h.splice(0,1),--f);return h[0]?Y(e,h,f):(e.s=3==R?-1:1,e.c=[e.e=0],e)},S.modulo=S.mod=function(e,t){var n,r,s=this;return e=new W(e,t),!s.c||!e.s||e.c&&!e.c[0]?new W(NaN):!e.c||s.c&&!s.c[0]?new W(s):(9==F?(r=e.s,e.s=1,n=E(s,e,0,3),e.s=r,n.s*=r):n=E(s,e,0,F),(e=s.minus(n.times(e))).c[0]||1!=F||(e.s=s.s),e)},S.multipliedBy=S.times=function(e,t){var n,r,s,i,u,c,f,h,p,g,m,y,b,w,E,A=this,v=A.c,x=(e=new W(e,t)).c;if(!(v&&x&&v[0]&&x[0]))return!A.s||!e.s||v&&!v[0]&&!x||x&&!x[0]&&!v?e.c=e.e=e.s=null:(e.s*=A.s,v&&x?(e.c=[0],e.e=0):e.c=e.e=null),e;for(r=d(A.e/a)+d(e.e/a),e.s*=A.s,(f=v.length)<(g=x.length)&&(b=v,v=x,x=b,s=f,f=g,g=s),s=f+g,b=[];s--;b.push(0));for(w=o,E=l,s=g;--s>=0;){for(n=0,m=x[s]%E,y=x[s]/E|0,i=s+(u=f);i>s;)n=((h=m*(h=v[--u]%E)+(c=y*h+(p=v[u]/E|0)*m)%E*E+b[i]+n)/w|0)+(c/E|0)+y*p,b[i--]=h%w;b[i]=n}return n?++r:b.splice(0,1),Y(e,b,r)},S.negated=function(){var e=new W(this);return e.s=-e.s||null,e},S.plus=function(e,t){var n,r=this,s=r.s;if(t=(e=new W(e,t)).s,!s||!t)return new W(NaN);if(s!=t)return e.s=-t,r.minus(e);var i=r.e/a,u=e.e/a,c=r.c,l=e.c;if(!i||!u){if(!c||!l)return new W(s/0);if(!c[0]||!l[0])return l[0]?e:new W(c[0]?r:0*s)}if(i=d(i),u=d(u),c=c.slice(),s=i-u){for(s>0?(u=i,n=l):(s=-s,n=c),n.reverse();s--;n.push(0));n.reverse()}for((s=c.length)-(t=l.length)<0&&(n=l,l=c,c=n,t=s),s=0;t;)s=(c[--t]=c[t]+l[t]+s)/o|0,c[t]=o===c[t]?0:c[t]%o;return s&&(c=[s].concat(c),++u),Y(e,c,u)},S.precision=S.sd=function(e,t){var n,r,s,i=this;if(null!=e&&e!==!!e)return g(e,1,f),null==t?t=R:g(t,0,8),q(new W(i),e,t);if(!(n=i.c))return null;if(r=(s=n.length-1)*a+1,s=n[s]){for(;s%10==0;s/=10,r--);for(s=n[0];s>=10;s/=10,r++);}return e&&i.e+1>r&&(r=i.e+1),r},S.shiftedBy=function(e){return g(e,-9007199254740991,u),this.times("1e"+e)},S.squareRoot=S.sqrt=function(){var e,t,n,r,s,i=this,o=i.c,a=i.s,u=i.e,c=$+4,l=new W("0.5");if(1!==a||!o||!o[0])return new W(!a||a<0&&(!o||o[0])?NaN:o?i:1/0);if(0==(a=Math.sqrt(+K(i)))||a==1/0?(((t=h(o)).length+u)%2==0&&(t+="0"),a=Math.sqrt(+t),u=d((u+1)/2)-(u<0||u%2),n=new W(t=a==1/0?"5e"+u:(t=a.toExponential()).slice(0,t.indexOf("e")+1)+u)):n=new W(a+""),n.c[0])for((a=(u=n.e)+c)<3&&(a=0);;)if(s=n,n=l.times(s.plus(E(i,s,c,1))),h(s.c).slice(0,a)===(t=h(n.c)).slice(0,a)){if(n.e<u&&--a,"9999"!=(t=t.slice(a-3,a+1))&&(r||"4999"!=t)){+t&&(+t.slice(1)||"5"!=t.charAt(0))||(q(n,n.e+$+2,1),e=!n.times(n).eq(i));break}if(!r&&(q(s,s.e+$+2,0),s.times(s).eq(i))){n=s;break}c+=4,a+=4,r=1}return q(n,n.e+$+1,R,e)},S.toExponential=function(e,t){return null!=e&&(g(e,0,f),e++),G(this,e,t,1)},S.toFixed=function(e,t){return null!=e&&(g(e,0,f),e=e+this.e+1),G(this,e,t)},S.toFormat=function(e,t,n){var r,i=this;if(null==n)null!=e&&t&&"object"==typeof t?(n=t,t=null):e&&"object"==typeof e?(n=e,e=t=null):n=M;else if("object"!=typeof n)throw Error(s+"Argument not an object: "+n);if(r=i.toFixed(e,t),i.c){var o,a=r.split("."),u=+n.groupSize,c=+n.secondaryGroupSize,l=n.groupSeparator||"",f=a[0],d=a[1],h=i.s<0,p=h?f.slice(1):f,g=p.length;if(c&&(o=u,u=c,c=o,g-=o),u>0&&g>0){for(o=g%u||u,f=p.substr(0,o);o<g;o+=u)f+=l+p.substr(o,u);c>0&&(f+=l+p.slice(o)),h&&(f="-"+f)}r=d?f+(n.decimalSeparator||"")+((c=+n.fractionGroupSize)?d.replace(new RegExp("\\d{"+c+"}\\B","g"),"$&"+(n.fractionGroupSeparator||"")):d):f}return(n.prefix||"")+r+(n.suffix||"")},S.toFraction=function(e){var t,n,r,i,o,u,l,f,d,p,g,m,y=this,b=y.c;if(null!=e&&(!(l=new W(e)).isInteger()&&(l.c||1!==l.s)||l.lt(T)))throw Error(s+"Argument "+(l.isInteger()?"out of range: ":"not an integer: ")+K(l));if(!b)return new W(y);for(t=new W(T),d=n=new W(T),r=f=new W(T),m=h(b),o=t.e=m.length-y.e-1,t.c[0]=c[(u=o%a)<0?a+u:u],e=!e||l.comparedTo(t)>0?o>0?t:d:l,u=L,L=1/0,l=new W(m),f.c[0]=0;p=E(l,t,0,1),1!=(i=n.plus(p.times(r))).comparedTo(e);)n=r,r=i,d=f.plus(p.times(i=d)),f=i,t=l.minus(p.times(i=t)),l=i;return i=E(e.minus(n),r,0,1),f=f.plus(i.times(d)),n=n.plus(i.times(r)),f.s=d.s=y.s,g=E(d,r,o*=2,R).minus(y).abs().comparedTo(E(f,n,o,R).minus(y).abs())<1?[d,r]:[f,n],L=u,g},S.toNumber=function(){return+K(this)},S.toPrecision=function(e,t){return null!=e&&g(e,1,f),G(this,e,t,2)},S.toString=function(e){var t,n=this,r=n.s,s=n.e;return null===s?r?(t="Infinity",r<0&&(t="-"+t)):t="NaN":(null==e?t=s<=D||s>=z?y(h(n.c),s):b(h(n.c),s,"0"):10===e&&j?t=b(h((n=q(new W(n),$+s+1,R)).c),n.e,"0"):(g(e,2,V.length,"Base"),t=A(b(h(n.c),s,"0"),10,e,r,!0)),r<0&&n.c[0]&&(t="-"+t)),t},S.valueOf=S.toJSON=function(){return K(this)},S._isBigNumber=!0,S[Symbol.toStringTag]="BigNumber",S[Symbol.for("nodejs.util.inspect.custom")]=S.valueOf,null!=w&&W.set(w),W}();const E=/^tuple(?<array>(\[(\d*)\])*)$/;function A(e){let t=e.type;if(E.test(e.type)&&"components"in e){t="(";const n=e.components.length;for(let r=0;r<n;r++){t+=A(e.components[r]),r<n-1&&(t+=", ")}const r=function(e,t){const n=e.exec(t);return n?.groups}(E,e.type);return t+=`)${r?.array??""}`,A({...e,type:t})}return"indexed"in e&&e.indexed&&(t=`${t} indexed`),e.name?`${t} ${e.name}`:t}function v(e){let t="";const n=e.length;for(let r=0;r<n;r++){t+=A(e[r]),r!==n-1&&(t+=", ")}return t}function x(e,{includeName:t=!1}={}){if("function"!==e.type&&"event"!==e.type&&"error"!==e.type)throw new j(e.type);return`${e.name}(${I(e.inputs,{includeName:t})})`}function I(e,{includeName:t=!1}={}){return e?e.map(e=>function(e,{includeName:t}){if(e.type.startsWith("tuple"))return`(${I(e.components,{includeName:t})})${e.type.slice(5)}`;return e.type+(t&&e.name?` ${e.name}`:"")}(e,{includeName:t})).join(t?", ":","):""}function C(e,{strict:t=!0}={}){return!!e&&("string"==typeof e&&(t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")))}function P(e){return C(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}const O="2.36.0";let B=({docsBaseUrl:e,docsPath:t="",docsSlug:n})=>t?`${e??"https://viem.sh"}${t}${n?`#${n}`:""}`:void 0,N=`viem@${O}`;class S extends Error{constructor(e,t={}){const n=t.cause instanceof S?t.cause.details:t.cause?.message?t.cause.message:t.details,r=t.cause instanceof S&&t.cause.docsPath||t.docsPath,s=B?.({...t,docsPath:r});super([e||"An error occurred.","",...t.metaMessages?[...t.metaMessages,""]:[],...s?[`Docs: ${s}`]:[],...n?[`Details: ${n}`]:[],...N?[`Version: ${N}`]:[]].join("\n"),t.cause?{cause:t.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),this.details=n,this.docsPath=r,this.metaMessages=t.metaMessages,this.name=t.name??this.name,this.shortMessage=e,this.version=O}walk(e){return T(this,e)}}function T(e,t){return t?.(e)?e:e&&"object"==typeof e&&"cause"in e&&void 0!==e.cause?T(e.cause,t):t?null:e}class $ extends S{constructor({data:e,params:t,size:n}){super([`Data size of ${n} bytes is too small for given parameters.`].join("\n"),{metaMessages:[`Params: (${I(t,{includeName:!0})})`,`Data: ${e} (${n} bytes)`],name:"AbiDecodingDataSizeTooSmallError"}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"params",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"size",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.data=e,this.params=t,this.size=n}}class R extends S{constructor(){super('Cannot decode zero data ("0x") with ABI parameters.',{name:"AbiDecodingZeroDataError"})}}class D extends S{constructor({expectedLength:e,givenLength:t,type:n}){super([`ABI encoding array length mismatch for type ${n}.`,`Expected length: ${e}`,`Given length: ${t}`].join("\n"),{name:"AbiEncodingArrayLengthMismatchError"})}}class z extends S{constructor({expectedSize:e,value:t}){super(`Size of bytes "${t}" (bytes${P(t)}) does not match expected size (bytes${e}).`,{name:"AbiEncodingBytesSizeMismatchError"})}}class U extends S{constructor({expectedLength:e,givenLength:t}){super(["ABI encoding params/values length mismatch.",`Expected length (params): ${e}`,`Given length (values): ${t}`].join("\n"),{name:"AbiEncodingLengthMismatchError"})}}class L extends S{constructor(e,{docsPath:t}={}){super([`Function ${e?`"${e}" `:""}not found on ABI.`,"Make sure you are using the correct ABI and that the function exists on it."].join("\n"),{docsPath:t,name:"AbiFunctionNotFoundError"})}}class _ extends S{constructor(e,{docsPath:t}){super([`Function "${e}" does not contain any \`outputs\` on ABI.`,"Cannot decode function result without knowing what the parameter types are.","Make sure you are using the correct ABI and that the function exists on it."].join("\n"),{docsPath:t,name:"AbiFunctionOutputsNotFoundError"})}}class F extends S{constructor(e,t){super("Found ambiguous types in overloaded ABI items.",{metaMessages:[`\`${e.type}\` in \`${x(e.abiItem)}\`, and`,`\`${t.type}\` in \`${x(t.abiItem)}\``,"","These types encode differently and cannot be distinguished at runtime.","Remove one of the ambiguous items in the ABI."],name:"AbiItemAmbiguityError"})}}class k extends S{constructor(e,{docsPath:t}){super([`Type "${e}" is not a valid encoding type.`,"Please provide a valid ABI type."].join("\n"),{docsPath:t,name:"InvalidAbiEncodingType"})}}class M extends S{constructor(e,{docsPath:t}){super([`Type "${e}" is not a valid decoding type.`,"Please provide a valid ABI type."].join("\n"),{docsPath:t,name:"InvalidAbiDecodingType"})}}class V extends S{constructor(e){super([`Value "${e}" is not a valid array.`].join("\n"),{name:"InvalidArrayError"})}}class j extends S{constructor(e){super([`"${e}" is not a valid definition type.`,'Valid types: "function", "event", "error"'].join("\n"),{name:"InvalidDefinitionTypeError"})}}class W extends S{constructor({offset:e,position:t,size:n}){super(`Slice ${"start"===t?"starting":"ending"} at offset "${e}" is out-of-bounds (size: ${n}).`,{name:"SliceOffsetOutOfBoundsError"})}}class G extends S{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${e}) exceeds padding size (${t}).`,{name:"SizeExceedsPaddingSizeError"})}}function Q(e,{dir:t,size:n=32}={}){return"string"==typeof e?Y(e,{dir:t,size:n}):function(e,{dir:t,size:n=32}={}){if(null===n)return e;if(e.length>n)throw new G({size:e.length,targetSize:n,type:"bytes"});const r=new Uint8Array(n);for(let s=0;s<n;s++){const i="right"===t;r[i?s:n-s-1]=e[i?s:e.length-s-1]}return r}(e,{dir:t,size:n})}function Y(e,{dir:t,size:n=32}={}){if(null===n)return e;const r=e.replace("0x","");if(r.length>2*n)throw new G({size:Math.ceil(r.length/2),targetSize:n,type:"hex"});return`0x${r["right"===t?"padEnd":"padStart"](2*n,"0")}`}class q extends S{constructor({max:e,min:t,signed:n,size:r,value:s}){super(`Number "${s}" is not in safe ${r?`${8*r}-bit ${n?"signed":"unsigned"} `:""}integer range ${e?`(${t} to ${e})`:`(above ${t})`}`,{name:"IntegerOutOfRangeError"})}}class K extends S{constructor(e){super(`Bytes value "${e}" is not a valid boolean. The bytes array must contain a single byte of either a 0 or 1 value.`,{name:"InvalidBytesBooleanError"})}}class H extends S{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:"SizeOverflowError"})}}function X(e,{dir:t="left"}={}){let n="string"==typeof e?e.replace("0x",""):e,r=0;for(let e=0;e<n.length-1&&"0"===n["left"===t?e:n.length-e-1].toString();e++)r++;return n="left"===t?n.slice(r):n.slice(0,n.length-r),"string"==typeof e?(1===n.length&&"right"===t&&(n=`${n}0`),`0x${n.length%2==1?`0${n}`:n}`):n}function Z(e,{size:t}){if(P(e)>t)throw new H({givenSize:P(e),maxSize:t})}function J(e,t={}){const{signed:n}=t;t.size&&Z(e,{size:t.size});const r=BigInt(e);if(!n)return r;const s=(e.length-2)/2;return r<=(1n<<8n*BigInt(s)-1n)-1n?r:r-BigInt(`0x${"f".padStart(2*s,"f")}`)-1n}const ee=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function te(e,t={}){const n=`0x${Number(e)}`;return"number"==typeof t.size?(Z(n,{size:t.size}),Q(n,{size:t.size})):n}function ne(e,t={}){let n="";for(let t=0;t<e.length;t++)n+=ee[e[t]];const r=`0x${n}`;return"number"==typeof t.size?(Z(r,{size:t.size}),Q(r,{dir:"right",size:t.size})):r}function re(e,t={}){const{signed:n,size:r}=t,s=BigInt(e);let i;r?i=n?(1n<<8n*BigInt(r)-1n)-1n:2n**(8n*BigInt(r))-1n:"number"==typeof e&&(i=BigInt(Number.MAX_SAFE_INTEGER));const o="bigint"==typeof i&&n?-i-1n:0;if(i&&s>i||s<o){const t="bigint"==typeof e?"n":"";throw new q({max:i?`${i}${t}`:void 0,min:`${o}${t}`,signed:n,size:r,value:`${e}${t}`})}const a=`0x${(n&&s<0?(1n<<BigInt(8*r))+BigInt(s):s).toString(16)}`;return r?Q(a,{size:r}):a}const se=new TextEncoder;function ie(e,t={}){return ne(se.encode(e),t)}const oe=new TextEncoder;function ae(e,t={}){return"number"==typeof e||"bigint"==typeof e?function(e,t){const n=re(e,t);return le(n)}(e,t):"boolean"==typeof e?function(e,t={}){const n=new Uint8Array(1);if(n[0]=Number(e),"number"==typeof t.size)return Z(n,{size:t.size}),Q(n,{size:t.size});return n}(e,t):C(e)?le(e,t):fe(e,t)}const ue={zero:48,nine:57,A:65,F:70,a:97,f:102};function ce(e){return e>=ue.zero&&e<=ue.nine?e-ue.zero:e>=ue.A&&e<=ue.F?e-(ue.A-10):e>=ue.a&&e<=ue.f?e-(ue.a-10):void 0}function le(e,t={}){let n=e;t.size&&(Z(n,{size:t.size}),n=Q(n,{dir:"right",size:t.size}));let r=n.slice(2);r.length%2&&(r=`0${r}`);const s=r.length/2,i=new Uint8Array(s);for(let e=0,t=0;e<s;e++){const n=ce(r.charCodeAt(t++)),s=ce(r.charCodeAt(t++));if(void 0===n||void 0===s)throw new S(`Invalid byte sequence ("${r[t-2]}${r[t-1]}" in "${r}").`);i[e]=16*n+s}return i}function fe(e,t={}){const n=oe.encode(e);return"number"==typeof t.size?(Z(n,{size:t.size}),Q(n,{dir:"right",size:t.size})):n}const de=BigInt(2**32-1),he=BigInt(32);function pe(e,t=!1){return t?{h:Number(e&de),l:Number(e>>he&de)}:{h:0|Number(e>>he&de),l:0|Number(e&de)}}function ge(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function me(e,...t){if(!((n=e)instanceof Uint8Array||ArrayBuffer.isView(n)&&"Uint8Array"===n.constructor.name))throw new Error("Uint8Array expected");
2
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
3
+ var n;if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function ye(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function be(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function we(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const Ee=(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])()?e=>e:function(e){for(let t=0;t<e.length;t++)e[t]=we(e[t]);return e};function Ae(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}(e)),me(e),e}class ve{}const xe=BigInt(0),Ie=BigInt(1),Ce=BigInt(2),Pe=BigInt(7),Oe=BigInt(256),Be=BigInt(113),Ne=[],Se=[],Te=[];for(let e=0,t=Ie,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],Ne.push(2*(5*r+n)),Se.push((e+1)*(e+2)/2%64);let s=xe;for(let e=0;e<7;e++)t=(t<<Ie^(t>>Pe)*Be)%Oe,t&Ce&&(s^=Ie<<(Ie<<BigInt(e))-Ie);Te.push(s)}const $e=function(e,t=!1){const n=e.length;let r=new Uint32Array(n),s=new Uint32Array(n);for(let i=0;i<n;i++){const{h:n,l:o}=pe(e[i],t);[r[i],s[i]]=[n,o]}return[r,s]}(Te,!0),Re=$e[0],De=$e[1],ze=(e,t,n)=>n>32?((e,t,n)=>t<<n-32|e>>>64-n)(e,t,n):((e,t,n)=>e<<n|t>>>32-n)(e,t,n),Ue=(e,t,n)=>n>32?((e,t,n)=>e<<n-32|t>>>64-n)(e,t,n):((e,t,n)=>t<<n|e>>>32-n)(e,t,n);class Le extends ve{constructor(e,t,n,r=!1,s=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=r,this.rounds=s,ge(n),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");var i;this.state=new Uint8Array(200),this.state32=(i=this.state,new Uint32Array(i.buffer,i.byteOffset,Math.floor(i.byteLength/4)))}clone(){return this._cloneInto()}keccak(){Ee(this.state32),function(e,t=24){const n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let t=0;t<10;t++)n[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){const r=(t+8)%10,s=(t+2)%10,i=n[s],o=n[s+1],a=ze(i,o,1)^n[r],u=Ue(i,o,1)^n[r+1];for(let n=0;n<50;n+=10)e[t+n]^=a,e[t+n+1]^=u}let t=e[2],s=e[3];for(let n=0;n<24;n++){const r=Se[n],i=ze(t,s,r),o=Ue(t,s,r),a=Ne[n];t=e[a],s=e[a+1],e[a]=i,e[a+1]=o}for(let t=0;t<50;t+=10){for(let r=0;r<10;r++)n[r]=e[t+r];for(let r=0;r<10;r++)e[t+r]^=~n[(r+2)%10]&n[(r+4)%10]}e[0]^=Re[r],e[1]^=De[r]}be(n)}(this.state32,this.rounds),Ee(this.state32),this.posOut=0,this.pos=0}update(e){ye(this),me(e=Ae(e));const{blockLen:t,state:n}=this,r=e.length;for(let s=0;s<r;){const i=Math.min(t-this.pos,r-s);for(let t=0;t<i;t++)n[this.pos++]^=e[s++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,128&t&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){ye(this,!1),me(e),this.finish();const t=this.state,{blockLen:n}=this;for(let r=0,s=e.length;r<s;){this.posOut>=n&&this.keccak();const i=Math.min(n-this.posOut,s-r);e.set(t.subarray(this.posOut,this.posOut+i),r),this.posOut+=i,r+=i}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return ge(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(function(e,t){me(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,be(this.state)}_cloneInto(e){const{blockLen:t,suffix:n,outputLen:r,rounds:s,enableXOF:i}=this;return e||(e=new Le(t,n,r,i,s)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=s,e.suffix=n,e.outputLen=r,e.enableXOF=i,e.destroyed=this.destroyed,e}}const _e=(e,t,n)=>function(e){const t=t=>e().update(Ae(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}(()=>new Le(t,e,n)),Fe=(()=>_e(1,136,32))();function ke(e,t){const n=t||"hex",r=Fe(C(e,{strict:!1})?ae(e):e);return"bytes"===n?r:function(e,t={}){return"number"==typeof e||"bigint"==typeof e?re(e,t):"string"==typeof e?ie(e,t):"boolean"==typeof e?te(e,t):ne(e,t)}(r)}function Me(e){return ke(ae(e))}const Ve=e=>{var t;return function(e){let t=!0,n="",r=0,s="",i=!1;for(let o=0;o<e.length;o++){const a=e[o];if(["(",")",","].includes(a)&&(t=!0),"("===a&&r++,")"===a&&r--,t)if(0!==r)" "!==a?(s+=a,n+=a):","!==e[o-1]&&","!==n&&",("!==n&&(n="",t=!1);else if(" "===a&&["event","function",""].includes(s))s="";else if(s+=a,")"===a){i=!0;break}}if(!i)throw new S("Unable to normalize signature.");return s}("string"==typeof e?e:"function"===(t=e).type?`function ${t.name}(${v(t.inputs)})${t.stateMutability&&"nonpayable"!==t.stateMutability?` ${t.stateMutability}`:""}${t.outputs?.length?` returns (${v(t.outputs)})`:""}`:"event"===t.type?`event ${t.name}(${v(t.inputs)})`:"error"===t.type?`error ${t.name}(${v(t.inputs)})`:"constructor"===t.type?`constructor(${v(t.inputs)})${"payable"===t.stateMutability?" payable":""}`:"fallback"===t.type?"fallback() external"+("payable"===t.stateMutability?" payable":""):"receive() external payable")};function je(e){return Me(Ve(e))}const We=je;class Ge extends S{constructor({address:e}){super(`Address "${e}" is invalid.`,{metaMessages:["- Address must be a hex value of 20 bytes (40 hex characters).","- Address must match its checksum counterpart."],name:"InvalidAddressError"})}}class Qe extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){const t=super.get(e);return super.has(e)&&void 0!==t&&(this.delete(e),super.set(e,t)),t}set(e,t){if(super.set(e,t),this.maxSize&&this.size>this.maxSize){const e=this.keys().next().value;e&&this.delete(e)}return this}}const Ye=new Qe(8192);function qe(e,t){if(Ye.has(`${e}.${t}`))return Ye.get(`${e}.${t}`);const n=e.substring(2).toLowerCase(),r=ke(fe(n),"bytes"),s=n.split("");for(let e=0;e<40;e+=2)r[e>>1]>>4>=8&&s[e]&&(s[e]=s[e].toUpperCase()),(15&r[e>>1])>=8&&s[e+1]&&(s[e+1]=s[e+1].toUpperCase());const i=`0x${s.join("")}`;return Ye.set(`${e}.${t}`,i),i}const Ke=/^0x[a-fA-F0-9]{40}$/,He=new Qe(8192);function Xe(e,t){const{strict:n=!0}=t??{},r=`${e}.${n}`;if(He.has(r))return He.get(r);const s=!(!Ke.test(e)||e.toLowerCase()!==e&&n&&qe(e)!==e);return He.set(r,s),s}function Ze(e){return"string"==typeof e[0]?Je(e):function(e){let t=0;for(const n of e)t+=n.length;const n=new Uint8Array(t);let r=0;for(const t of e)n.set(t,r),r+=t.length;return n}(e)}function Je(e){return`0x${e.reduce((e,t)=>e+t.replace("0x",""),"")}`}function et(e,t,n,{strict:r}={}){return C(e,{strict:!1})?function(e,t,n,{strict:r}={}){tt(e,t);const s=`0x${e.replace("0x","").slice(2*(t??0),2*(n??e.length))}`;r&&nt(s,t,n);return s}(e,t,n,{strict:r}):rt(e,t,n,{strict:r})}function tt(e,t){if("number"==typeof t&&t>0&&t>P(e)-1)throw new W({offset:t,position:"start",size:P(e)})}function nt(e,t,n){if("number"==typeof t&&"number"==typeof n&&P(e)!==n-t)throw new W({offset:n,position:"end",size:P(e)})}function rt(e,t,n,{strict:r}={}){tt(e,t);const s=e.slice(t,n);return r&&nt(s,t,n),s}const st=/^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/;function it(e,t){if(e.length!==t.length)throw new U({expectedLength:e.length,givenLength:t.length});const n=function({params:e,values:t}){const n=[];for(let r=0;r<e.length;r++)n.push(ot({param:e[r],value:t[r]}));return n}({params:e,values:t}),r=at(n);return 0===r.length?"0x":r}function ot({param:e,value:t}){const n=ut(e.type);if(n){const[r,s]=n;return function(e,{length:t,param:n}){const r=null===t;if(!Array.isArray(e))throw new V(e);if(!r&&e.length!==t)throw new D({expectedLength:t,givenLength:e.length,type:`${n.type}[${t}]`});let s=!1;const i=[];for(let t=0;t<e.length;t++){const r=ot({param:n,value:e[t]});r.dynamic&&(s=!0),i.push(r)}if(r||s){const e=at(i);if(r){const t=re(i.length,{size:32});return{dynamic:!0,encoded:i.length>0?Ze([t,e]):t}}if(s)return{dynamic:!0,encoded:e}}return{dynamic:!1,encoded:Ze(i.map(({encoded:e})=>e))}}(t,{length:r,param:{...e,type:s}})}if("tuple"===e.type)return function(e,{param:t}){let n=!1;const r=[];for(let s=0;s<t.components.length;s++){const i=t.components[s],o=ot({param:i,value:e[Array.isArray(e)?s:i.name]});r.push(o),o.dynamic&&(n=!0)}return{dynamic:n,encoded:n?at(r):Ze(r.map(({encoded:e})=>e))}}(t,{param:e});if("address"===e.type)return function(e){if(!Xe(e))throw new Ge({address:e});return{dynamic:!1,encoded:Y(e.toLowerCase())}}(t);if("bool"===e.type)return function(e){if("boolean"!=typeof e)throw new S(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:Y(te(e))}}(t);if(e.type.startsWith("uint")||e.type.startsWith("int")){const n=e.type.startsWith("int"),[,,r="256"]=st.exec(e.type)??[];return function(e,{signed:t,size:n=256}){if("number"==typeof n){const r=2n**(BigInt(n)-(t?1n:0n))-1n,s=t?-r-1n:0n;if(e>r||e<s)throw new q({max:r.toString(),min:s.toString(),signed:t,size:n/8,value:e.toString()})}return{dynamic:!1,encoded:re(e,{size:32,signed:t})}}(t,{signed:n,size:Number(r)})}if(e.type.startsWith("bytes"))return function(e,{param:t}){const[,n]=t.type.split("bytes"),r=P(e);if(!n){let t=e;return r%32!=0&&(t=Y(t,{dir:"right",size:32*Math.ceil((e.length-2)/2/32)})),{dynamic:!0,encoded:Ze([Y(re(r,{size:32})),t])}}if(r!==Number.parseInt(n,10))throw new z({expectedSize:Number.parseInt(n,10),value:e});return{dynamic:!1,encoded:Y(e,{dir:"right"})}}(t,{param:e});if("string"===e.type)return function(e){const t=ie(e),n=Math.ceil(P(t)/32),r=[];for(let e=0;e<n;e++)r.push(Y(et(t,32*e,32*(e+1)),{dir:"right"}));return{dynamic:!0,encoded:Ze([Y(re(P(t),{size:32})),...r])}}(t);throw new k(e.type,{docsPath:"/docs/contract/encodeAbiParameters"})}function at(e){let t=0;for(let n=0;n<e.length;n++){const{dynamic:r,encoded:s}=e[n];t+=r?32:P(s)}const n=[],r=[];let s=0;for(let i=0;i<e.length;i++){const{dynamic:o,encoded:a}=e[i];o?(n.push(re(t+s,{size:32})),r.push(a),s+=P(a)):n.push(a)}return Ze([...n,...r])}function ut(e){const t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}const ct=e=>et(je(e),0,4);function lt(e){const{abi:t,args:n=[],name:r}=e,s=C(r,{strict:!1}),i=t.filter(e=>s?"function"===e.type?ct(e)===r:"event"===e.type&&We(e)===r:"name"in e&&e.name===r);if(0===i.length)return;if(1===i.length)return i[0];let o;for(const e of i){if(!("inputs"in e))continue;if(!n||0===n.length){if(!e.inputs||0===e.inputs.length)return e;continue}if(!e.inputs)continue;if(0===e.inputs.length)continue;if(e.inputs.length!==n.length)continue;if(n.every((t,n)=>{const r="inputs"in e&&e.inputs[n];return!!r&&ft(t,r)})){if(o&&"inputs"in o&&o.inputs){const t=dt(e.inputs,o.inputs,n);if(t)throw new F({abiItem:e,type:t[0]},{abiItem:o,type:t[1]})}o=e}}return o||i[0]}function ft(e,t){const n=typeof e,r=t.type;switch(r){case"address":return Xe(e,{strict:!1});case"bool":return"boolean"===n;case"function":case"string":return"string"===n;default:return"tuple"===r&&"components"in t?Object.values(t.components).every((t,n)=>ft(Object.values(e)[n],t)):/^u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/.test(r)?"number"===n||"bigint"===n:/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/.test(r)?"string"===n||e instanceof Uint8Array:!!/[a-z]+[1-9]{0,3}(\[[0-9]{0,}\])+$/.test(r)&&(Array.isArray(e)&&e.every(e=>ft(e,{...t,type:r.replace(/(\[[0-9]{0,}\])$/,"")})))}}function dt(e,t,n){for(const r in e){const s=e[r],i=t[r];if("tuple"===s.type&&"tuple"===i.type&&"components"in s&&"components"in i)return dt(s.components,i.components,n[r]);const o=[s.type,i.type];if((()=>!(!o.includes("address")||!o.includes("bytes20"))||(o.includes("address")&&o.includes("string")||!(!o.includes("address")||!o.includes("bytes")))&&Xe(n[r],{strict:!1}))())return o}}const ht="/docs/contract/encodeFunctionData";function pt(e){const{args:t}=e,{abi:n,functionName:r}=1===e.abi.length&&e.functionName?.startsWith("0x")?e:function(e){const{abi:t,args:n,functionName:r}=e;let s=t[0];if(r){const e=lt({abi:t,args:n,name:r});if(!e)throw new L(r,{docsPath:ht});s=e}if("function"!==s.type)throw new L(void 0,{docsPath:ht});return{abi:[s],functionName:ct(x(s))}}(e),s=n[0];return Je([r,("inputs"in s&&s.inputs?it(s.inputs,t??[]):void 0)??"0x"])}class gt extends S{constructor({offset:e}){super(`Offset \`${e}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class mt extends S{constructor({length:e,position:t}){super(`Position \`${t}\` is out of bounds (\`0 < position < ${e}\`).`,{name:"PositionOutOfBoundsError"})}}class yt extends S{constructor({count:e,limit:t}){super(`Recursive read limit of \`${t}\` exceeded (recursive read count: \`${e}\`).`,{name:"RecursiveReadLimitExceededError"})}}const bt={bytes:new Uint8Array,dataView:new DataView(new ArrayBuffer(0)),position:0,positionReadCount:new Map,recursiveReadCount:0,recursiveReadLimit:Number.POSITIVE_INFINITY,assertReadLimit(){if(this.recursiveReadCount>=this.recursiveReadLimit)throw new yt({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new mt({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new gt({offset:e});const t=this.position-e;this.assertPosition(t),this.position=t},getReadCount(e){return this.positionReadCount.get(e||this.position)||0},incrementPosition(e){if(e<0)throw new gt({offset:e});const t=this.position+e;this.assertPosition(t),this.position=t},inspectByte(e){const t=e??this.position;return this.assertPosition(t),this.bytes[t]},inspectBytes(e,t){const n=t??this.position;return this.assertPosition(n+e-1),this.bytes.subarray(n,n+e)},inspectUint8(e){const t=e??this.position;return this.assertPosition(t),this.bytes[t]},inspectUint16(e){const t=e??this.position;return this.assertPosition(t+1),this.dataView.getUint16(t)},inspectUint24(e){const t=e??this.position;return this.assertPosition(t+2),(this.dataView.getUint16(t)<<8)+this.dataView.getUint8(t+2)},inspectUint32(e){const t=e??this.position;return this.assertPosition(t+3),this.dataView.getUint32(t)},pushByte(e){this.assertPosition(this.position),this.bytes[this.position]=e,this.position++},pushBytes(e){this.assertPosition(this.position+e.length-1),this.bytes.set(e,this.position),this.position+=e.length},pushUint8(e){this.assertPosition(this.position),this.bytes[this.position]=e,this.position++},pushUint16(e){this.assertPosition(this.position+1),this.dataView.setUint16(this.position,e),this.position+=2},pushUint24(e){this.assertPosition(this.position+2),this.dataView.setUint16(this.position,e>>8),this.dataView.setUint8(this.position+2,255&e),this.position+=3},pushUint32(e){this.assertPosition(this.position+3),this.dataView.setUint32(this.position,e),this.position+=4},readByte(){this.assertReadLimit(),this._touch();const e=this.inspectByte();return this.position++,e},readBytes(e,t){this.assertReadLimit(),this._touch();const n=this.inspectBytes(e);return this.position+=t??e,n},readUint8(){this.assertReadLimit(),this._touch();const e=this.inspectUint8();return this.position+=1,e},readUint16(){this.assertReadLimit(),this._touch();const e=this.inspectUint16();return this.position+=2,e},readUint24(){this.assertReadLimit(),this._touch();const e=this.inspectUint24();return this.position+=3,e},readUint32(){this.assertReadLimit(),this._touch();const e=this.inspectUint32();return this.position+=4,e},get remaining(){return this.bytes.length-this.position},setPosition(e){const t=this.position;return this.assertPosition(e),this.position=e,()=>this.position=t},_touch(){if(this.recursiveReadLimit===Number.POSITIVE_INFINITY)return;const e=this.getReadCount();this.positionReadCount.set(this.position,e+1),e>0&&this.recursiveReadCount++}};function wt(e,t={}){void 0!==t.size&&Z(e,{size:t.size});return J(ne(e,t),t)}function Et(e,t={}){let n=e;if(void 0!==t.size&&(Z(n,{size:t.size}),n=X(n)),n.length>1||n[0]>1)throw new K(n);return Boolean(n[0])}function At(e,t={}){void 0!==t.size&&Z(e,{size:t.size});return function(e,t={}){return Number(J(e,t))}(ne(e,t),t)}function vt(e,t){const n="string"==typeof t?le(t):t,r=function(e,{recursiveReadLimit:t=8192}={}){const n=Object.create(bt);return n.bytes=e,n.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength),n.positionReadCount=new Map,n.recursiveReadLimit=t,n}(n);if(0===P(n)&&e.length>0)throw new R;if(P(t)&&P(t)<32)throw new $({data:"string"==typeof t?t:ne(t),params:e,size:P(t)});let s=0;const i=[];for(let t=0;t<e.length;++t){const n=e[t];r.setPosition(s);const[o,a]=xt(r,n,{staticPosition:0});s+=a,i.push(o)}return i}function xt(e,t,{staticPosition:n}){const r=ut(t.type);if(r){const[s,i]=r;return function(e,t,{length:n,staticPosition:r}){if(!n){const n=r+At(e.readBytes(Ct)),s=n+It;e.setPosition(n);const i=At(e.readBytes(It)),o=Pt(t);let a=0;const u=[];for(let n=0;n<i;++n){e.setPosition(s+(o?32*n:a));const[r,i]=xt(e,t,{staticPosition:s});a+=i,u.push(r)}return e.setPosition(r+32),[u,32]}if(Pt(t)){const s=r+At(e.readBytes(Ct)),i=[];for(let r=0;r<n;++r){e.setPosition(s+32*r);const[n]=xt(e,t,{staticPosition:s});i.push(n)}return e.setPosition(r+32),[i,32]}let s=0;const i=[];for(let o=0;o<n;++o){const[n,o]=xt(e,t,{staticPosition:r+s});s+=o,i.push(n)}return[i,s]}(e,{...t,type:i},{length:s,staticPosition:n})}if("tuple"===t.type)return function(e,t,{staticPosition:n}){const r=0===t.components.length||t.components.some(({name:e})=>!e),s=r?[]:{};let i=0;if(Pt(t)){const o=n+At(e.readBytes(Ct));for(let n=0;n<t.components.length;++n){const a=t.components[n];e.setPosition(o+i);const[u,c]=xt(e,a,{staticPosition:o});i+=c,s[r?n:a?.name]=u}return e.setPosition(n+32),[s,32]}for(let o=0;o<t.components.length;++o){const a=t.components[o],[u,c]=xt(e,a,{staticPosition:n});s[r?o:a?.name]=u,i+=c}return[s,i]}(e,t,{staticPosition:n});if("address"===t.type)return function(e){const t=e.readBytes(32);return[qe(ne(rt(t,-20))),32]}(e);if("bool"===t.type)return function(e){return[Et(e.readBytes(32),{size:32}),32]}(e);if(t.type.startsWith("bytes"))return function(e,t,{staticPosition:n}){const[r,s]=t.type.split("bytes");if(!s){const t=At(e.readBytes(32));e.setPosition(n+t);const r=At(e.readBytes(32));if(0===r)return e.setPosition(n+32),["0x",32];const s=e.readBytes(r);return e.setPosition(n+32),[ne(s),32]}const i=ne(e.readBytes(Number.parseInt(s,10),32));return[i,32]}(e,t,{staticPosition:n});if(t.type.startsWith("uint")||t.type.startsWith("int"))return function(e,t){const n=t.type.startsWith("int"),r=Number.parseInt(t.type.split("int")[1]||"256",10),s=e.readBytes(32);return[r>48?wt(s,{signed:n}):At(s,{signed:n}),32]}(e,t);if("string"===t.type)return function(e,{staticPosition:t}){const n=At(e.readBytes(32)),r=t+n;e.setPosition(r);const s=At(e.readBytes(32));if(0===s)return e.setPosition(t+32),["",32];const i=e.readBytes(s,32),o=function(e,t={}){let n=e;return void 0!==t.size&&(Z(n,{size:t.size}),n=X(n,{dir:"right"})),(new TextDecoder).decode(n)}(X(i));return e.setPosition(t+32),[o,32]}(e,{staticPosition:n});throw new M(t.type,{docsPath:"/docs/contract/decodeAbiParameters"})}const It=32,Ct=32;function Pt(e){const{type:t}=e;if("string"===t)return!0;if("bytes"===t)return!0;if(t.endsWith("[]"))return!0;if("tuple"===t)return e.components?.some(Pt);const n=ut(e.type);return!(!n||!Pt({...e,type:n[1]}))}const Ot="/docs/contract/decodeFunctionResult";const Bt="0x0000000000000000000000000000000000000000";class Nt extends Error{constructor(e){super(e.message),this.name="SwapError",this.code=e.code,this.details=e.details,Error.captureStackTrace&&Error.captureStackTrace(this,Nt)}}const St={V2:0,V3:1},Tt="0x0000000000000000000000000000000000000001",$t="0x0000000000000000000000000000000000000000",Rt=5,Dt="https://api-public.bitzy.app",zt={3637:{BITZY_V3:"0xA5E0AE4e5103dc71cA290AA3654830442357A489",BITZY_V2:"0x07c49Ade88b40f1Ac05707f236d7706f834F6BDB",AVOCADO_V2:"0xA4B4cDeC4fE2839d3D3a49Ad5E20c21c01A31091"},3636:{BITZY_V3:"0xA5E0AE4e5103dc71cA290AA3654830442357A489",BITZY_V2:"0x07c49Ade88b40f1Ac05707f236d7706f834F6BDB",AVOCADO_V2:"0xA4B4cDeC4fE2839d3D3a49Ad5E20c21c01A31091"}},Ut={3637:{factoryAddress:"0xDF2CA43f59fd92874e6C1ef887f7E14cb1f354dD",v3FactoryAddress:"0xa8C00286d8d37131c1d033dEeE2F754148932800",v3PositionManagerAddress:"0x76F3e7e326479Ef559996Cf5ab0aCB79Be4626FD",v3WalletHelperAddress:"0xd9Db96Aa882Da764feFff3eE427701B0337e8Ae7",routerAddress:"0x41207Eadf1932966Ff75bdc35e55D2C6734E47D4",aggregatorAddress:"0x5a0690AC82AAAA2e25bC130E900CD31eE9B67DB8",otcAddress:"0xe97ED77EB36A09c37B57D69A5000d8831167A854",memeTokenGenerator:"0x1cb880329265c7A5deDaD6301b1fbd2684CDd200",bitzyQueryAddress:"0x5b5079587501Bd85d3CDf5bFDf299f4eaAe98c23",wrappedAddress:"0x0D2437F93Fed6EA64Ef01cCde385FB1263910C56",nativeAddress:"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",gasLimit:BigInt(5e10)},3636:{factoryAddress:"0x472F9A40F47e0e0F770b224AeC2DD093cf5783aC",v3FactoryAddress:"0xc89e6aD4aD42Eeb82dfBA4c301CDaEDfd794A778",v3PositionManagerAddress:"0xA05E35Fa8997852E6a4A073461E36db1AA725D39",v3WalletHelperAddress:"0x232182B50E1d3c037b3E0bdbd89226d7730cFe0e",routerAddress:"0x07c49Ade88b40f1Ac05707f236d7706f834F6BDB",aggregatorAddress:"0x33B1Ed34c11910F767B15eBAbAB782D61FB2C5Ea",otcAddress:"0xB582f4B568f13F29Bba7696Fc352E293952D4b7E",memeTokenGenerator:"0xc76b4a09BecA8b34D94dE8BA27AeeF652FA3D2fC",bitzyQueryAddress:"0x2ad4b8912fb4Fe93f79BbCb3Aa6B8C39025FdfCC",wrappedAddress:"0x233631132FD56c8f86D1FC97F0b82420a8d20af3",nativeAddress:"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",gasLimit:BigInt(5e10)}},Lt={3637:{types:[1,2],enabledSources:[1]},3636:{types:[1,2],enabledSources:[1]}},_t=e=>Lt[e]||{types:[1,2],enabledSources:[1]},Ft=e=>Ut[e],kt=Ut,Mt=zt[3637]||{},Vt={PATH_V3:"/api/sdk/bestpath/split",ASSET_MINIMUM:"/api/sdk/asset/minimum"},jt={INVALID_TOKENS:"INVALID_TOKENS",INVALID_AMOUNT:"INVALID_AMOUNT",NETWORK_NOT_SUPPORTED:"NETWORK_NOT_SUPPORTED",API_ERROR:"API_ERROR",QUERY_ERROR:"QUERY_ERROR",INSUFFICIENT_LIQUIDITY:"INSUFFICIENT_LIQUIDITY"};class Wt{constructor(e){this.config=e}static getInstance(e){if(!Wt.instance){console.log(3232,process.env.NEXT_PUBLIC_BITZY_API_KEY);const t={...e,headers:{...process.env.NEXT_PUBLIC_BITZY_API_KEY&&{"authen-key":process.env.NEXT_PUBLIC_BITZY_API_KEY},...e.headers}};Wt.instance=new Wt(t)}return Wt.instance}static resetInstance(){Wt.instance=null}async request(e,t={}){const n=new AbortController,r=setTimeout(()=>n.abort(),this.config.timeout);try{const s=await fetch(`${this.config.baseUrl}${e}`,{...t,signal:n.signal,headers:{"Content-Type":"application/json",...this.config.headers,...t.headers}});if(clearTimeout(r),!s.ok)throw new Error(`HTTP ${s.status}: ${s.statusText}`);return await s.json()}catch(t){if(clearTimeout(r),t instanceof Error){if("AbortError"===t.name)throw new Nt({message:"Request timeout",code:jt.API_ERROR,details:{endpoint:e,timeout:this.config.timeout}});throw new Nt({message:t.message,code:jt.API_ERROR,details:{endpoint:e,originalError:t}})}throw new Nt({message:"Unknown API error",code:jt.API_ERROR,details:{endpoint:e,originalError:t}})}}async getPathV3(e,t,n,r,s){const i={src:e.address,dest:t.address,amount:n,typeId:r,sourceId:s},o=this.buildQueryString(i);return this.request(`${Vt.PATH_V3}?${o}`,{method:"GET"})}async getAssetMinimum(){return this.request(Vt.ASSET_MINIMUM,{method:"GET"})}buildQueryString(e){return Object.keys(e).reduce((t,n)=>[...t,`${n}=${Array.isArray(e[n])?'["'+e[n].map(e=>e).join('","')+'"]':e[n]}`],[]).join("&")}}Wt.instance=null;let Gt=null;const Qt={3637:["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE","0x0D2437F93Fed6EA64Ef01cCde385FB1263910C56","0x29eE6138DD4C9815f46D34a4A1ed48F46758A402","0x9BC574a6f1170e90D80826D86a6126d59198A3Ef","0xA0b86a33E6441b8c4C8C0C4C0C4C0C4C0C4C0C4C","0xdAC17F958D2ee523a2206206994597C13D831ec7"],3636:["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE","0x233631132FD56c8f86D1FC97F0b82420a8d20af3","0xA0b86a33E6441b8c4C8C0C4C0C4C0C4C0C4C0C4C","0xdAC17F958D2ee523a2206206994597C13D831ec7"]};function Yt(e,t){if(!e?.address)return!1;const n=Qt[t];return!!n&&n.some(t=>t.toLowerCase()===e.address.toLowerCase())}function qt(e,t,n,r=5){const s=Yt(e,n),i=Yt(t,n);return s&&i?r:1}async function Kt(e,t,n,r,s,i,o=5){try{console.log("Fetching online partCount data...");const a=await async function(e,t){const n=Date.now();if(Gt&&n<Gt.expiresAt)return console.log("Using cached minimum amounts data"),Gt.data;console.log("Fetching fresh minimum amounts data from API");const r=Wt.getInstance({baseUrl:e,timeout:5e3,headers:{...t&&{"authen-key":t}}}),s=await r.getAssetMinimum();if(!s.success)throw new Error(`API request failed: ${s.error||"Unknown error"}`);return Gt={data:s.data||[],timestamp:n,expiresAt:n+3e5},Gt.data}(s,i),u=a.find(t=>t.token?.toLowerCase()===e.address.toLowerCase()),c=a.find(e=>e.token?.toLowerCase()===t.address.toLowerCase()),l=new w(n);return u&&c&&l.gte(u.minimumAmount)&&l.gte(c.minimumAmount)?(console.log("Amount meets minimum threshold for both tokens, using partCount = 5"),5):(console.log("Amount below minimum threshold or missing data, falling back to offline logic"),qt(e,t,r,o))}catch(n){return console.warn("Failed to fetch online partCount data:",n),console.log("Falling back to offline partCount logic"),qt(e,t,r,o)}}async function Ht(e,t,n,r,s,i=5,o){try{return await Kt(e,t,n,r,s,o,i)}catch(e){return console.warn("Online partCount failed, using offline fallback:",e),i}}function Xt(e,t,n){if(0===t)return 1/0;return e/n/t*100}function Zt(e,t){return!e||isNaN(Number(e))?new w(0):new w(e).times(new w(10).pow(t))}function Jt(e,t){return e.address.toLowerCase()===t.toLowerCase()}function en(e,t){return e.address.toLowerCase()===t.toLowerCase()}function tn(e,t){return e&&t&&e.address&&t.address&&e.address!==t.address&&e.chainId===t.chainId}function nn(e){if(!e||isNaN(Number(e)))return!1;const t=new w(e);return t.gt(0)&&t.isFinite()}function rn(e,t){let n;const r=(...r)=>{clearTimeout(n),n=setTimeout(()=>e(...r),t)};return r.cancel=()=>{clearTimeout(n)},r}const sn=[{inputs:[{internalType:"uint256",name:"srcAmount",type:"uint256"},{internalType:"bytes",name:"encodedRoutes",type:"bytes"},{internalType:"uint256",name:"parts",type:"uint256"}],name:"splitQuery",outputs:[{components:[{internalType:"uint256",name:"amountOut",type:"uint256"},{internalType:"uint256",name:"bestIndex",type:"uint256"}],internalType:"struct BitzyQueryV2.OneRoute",name:"",type:"tuple"},{components:[{internalType:"uint256[]",name:"distribution",type:"uint256[]"},{internalType:"uint256",name:"amountOut",type:"uint256"}],internalType:"struct BitzyQueryV2.SplitRoute",name:"",type:"tuple"}],stateMutability:"nonpayable",type:"function"}];class on{constructor(e){this.config=e}async fetchRoute(e){const{amountIn:t,srcToken:n,dstToken:r,chainId:s,partCount:i,forcePartCount:o}=e,a=o||i||this.getPartCount(n,r,s,this.config.defaultPartCount);if(!tn(n,r))throw new Nt({message:"Invalid tokens provided",code:jt.INVALID_TOKENS,details:{srcToken:n,dstToken:r}});if(!nn(t))throw new Nt({message:"Invalid amount provided",code:jt.INVALID_AMOUNT,details:{amountIn:t}});const u=Zt(t,n.decimals),{routerAddress:c,bitzyQueryAddress:l,wrappedAddress:f,nativeAddress:d}=this.config.config,h=Jt(n,d),p=Jt(r,d);if(h&&en(r,f)||p&&en(n,f)){const e=h?"wrap":"unwrap",t=u;return{routes:[[{routerAddress:c,lpAddress:Bt,fromToken:n.address,toToken:r.address,from:n.address,to:r.address,part:"100000000",amountAfterFee:"10000",dexInterface:0}]],distributions:[a],amountOutRoutes:[t],amountOutBN:t,amountInParts:[u],isAmountOutError:!1,isWrap:e}}const g=h?{...n,address:f}:n,m=p?{...r,address:f}:r;try{const t=await this.config.apiClient.getPathV3(g,m,u.toFixed(0),e.types||[1,2],e.enabledSources||[1]),{hops:n,validPath:r}=t.data;if(0===n.length)return console.log("SDK: No hops found"),{routes:[],distributions:[],amountOutRoutes:[],amountOutBN:new w(0),amountInParts:[],isAmountOutError:!0};console.log("SDK: hops.length =",n.length),console.log("SDK: validPath.length =",r.length),console.log("SDK: partCount =",a);const s=it([{type:"tuple[][]",components:[{type:"address",name:"src"},{type:"address",name:"dest"},{type:"uint8",name:"typeId"},{type:"uint8",name:"sourceId"},{type:"bytes",name:"path"}]}],[n]);let i=new w(0),o=[],c=[];if(this.config.publicClient)try{console.log("SDK: Calling splitQuery with:",{bitzyQueryAddress:l,amountIn:u.toFixed(0),partCount:a,encodedRoutesLength:s.length});const e=pt({abi:sn,functionName:"splitQuery",args:[u.toFixed(0),s,a]}),t=await this.config.publicClient.call({to:l,data:e,gas:50000000000n,gasPrice:void 0});if(console.log("SDK: Contract call result:",t),t.data){const e=function(e){const{abi:t,args:n,functionName:r,data:s}=e;let i=t[0];if(r){const e=lt({abi:t,args:n,name:r});if(!e)throw new L(r,{docsPath:Ot});i=e}if("function"!==i.type)throw new L(void 0,{docsPath:Ot});if(!i.outputs)throw new _(i.name,{docsPath:Ot});const o=vt(i.outputs,s);return o&&o.length>1?o:o&&1===o.length?o[0]:void 0}({abi:sn,functionName:"splitQuery",data:t.data}),n=e[1];if(n&&n.amountOut){i=new w(n.amountOut.toString());let e=n.distribution.map(e=>new w(e.toString()).toNumber());c=r.reduce((t,n,r)=>(e[r]>0&&t.push(n.map((e,t,n)=>({routerAddress:Mt[e.source+"_"+e.type]||Bt,lpAddress:e.pool||Bt,fromToken:e.src,toToken:e.dest,from:t>0||"V3"===e.type||e.src===f.toLowerCase()?$t:Tt,to:t<n.length-1||t===n.length-1&&e.dest===f.toLowerCase()?$t:Tt,part:"100000000",amountAfterFee:new w(1e4).minus(new w(e.fee||0).dividedBy(100)).toFixed(),dexInterface:St[e.type]||0}))),t),[]),o=e.filter(e=>e>0)}}}catch(e){console.error("SDK: splitQuery contract call failed:",e),i=new w(0),o=[],c=[]}else console.error("SDK: No publicClient available - this is the problem!"),i=new w(0),o=[],c=[];const d=o.map(e=>i.times(e).dividedBy(a).dp(0,w.ROUND_DOWN)),h=o.map(e=>u.times(e).dividedBy(a).dp(0,w.ROUND_DOWN));return{routes:c,distributions:o,amountOutRoutes:d,amountOutBN:i,amountInParts:h,isAmountOutError:!1}}catch(t){throw new Nt({message:"Failed to fetch swap route",code:jt.API_ERROR,details:{originalError:t,options:e}})}}getSupportedNetworks(){return Object.keys(kt).map(Number)}getNetworkConfig(e){return this.config.config}getPartCount(e,t,n,r){return qt(e,t,n,r)}}async function an(e,t={}){const{apiBaseUrl:n=Dt,defaultPartCount:r=Rt,timeout:s=3e4,headers:i={}}=t,o=e.chainId,a=Ft(o);if(!a)throw new Error(`Unsupported network: ${o}`);const u=Wt.getInstance({baseUrl:n,timeout:s,headers:i});return new on({config:{routerAddress:a.routerAddress,bitzyQueryAddress:a.bitzyQueryAddress,wrappedAddress:a.wrappedAddress,nativeAddress:a.nativeAddress},defaultPartCount:r,apiClient:u}).fetchRoute(e)}const un=(t,n,r,s,i={})=>{const o=e.useMemo(()=>({}),[]),a=e.useMemo(()=>({routerAddress:Bt,bitzyQueryAddress:Bt,wrappedAddress:Bt,nativeAddress:Bt}),[]),{apiBaseUrl:u,addressConfig:c,defaultPartCount:l,timeout:f,headers:d,refreshInterval:h,publicClient:p,configTypes:g,configEnabledSources:m,forcePartCount:y,useOnlinePartCount:b}=e.useMemo(()=>{const{apiBaseUrl:e=Dt,config:t=a,defaultPartCount:n=5,timeout:r=3e4,headers:s=o,refreshInterval:u=1e4,publicClient:c,types:l,enabledSources:f,forcePartCount:d,useOnlinePartCount:h=!1}=i;return{apiBaseUrl:e,addressConfig:t,defaultPartCount:n,timeout:r,headers:s,refreshInterval:u,publicClient:c,configTypes:l,configEnabledSources:f,forcePartCount:d,useOnlinePartCount:h}},[i,o,a]),E=e.useMemo(()=>_t(s),[s]),A=e.useMemo(()=>g??E.types,[g,E.types]),v=e.useMemo(()=>m??E.enabledSources,[m,E.enabledSources]);e.useEffect(()=>{console.log("config",i)},[i]),e.useEffect(()=>{console.log("srcToken",t)},[t]),e.useEffect(()=>{console.log("dstToken",n)},[n]),e.useEffect(()=>{console.log("amountIn",r)},[r]),e.useEffect(()=>{console.log("chainId",s)},[s]),e.useEffect(()=>{console.log("apiBaseUrl",u)},[u]),e.useEffect(()=>{console.log("addressConfig",c)},[c]),e.useEffect(()=>{console.log("defaultPartCount",l)},[l]),e.useEffect(()=>{console.log("timeout",f)},[f]),e.useEffect(()=>{console.log("headers",d)},[d]),e.useEffect(()=>{console.log("types",A)},[A]),e.useEffect(()=>{console.log("enabledSources",v)},[v]);const[x,I]=e.useState(new w(0)),[C,P]=e.useState([]),[O,B]=e.useState([]),[N,S]=e.useState([]),[T,$]=e.useState([]),[R,D]=e.useState(!1),[z,U]=e.useState(!1),[L,_]=e.useState(),[F,k]=e.useState(!1),[M,V]=e.useState(null),[j,W]=e.useState(null),G=e.useMemo(()=>(console.log("partCount",0,b),b?null!==j?j:qt(t,n,s,l):(console.log("partCount",1,y),void 0!==y?y:(console.log("partCount",2,l),qt(t,n,s,l)))),[l,y,b,j,t,n,s]);e.useEffect(()=>{if(!(b&&t&&n&&r))return void W(null);(async()=>{try{const e=await Ht(t,n,r,s,u,l);W(e)}catch(e){console.warn("Failed to fetch online partCount:",e),W(null)}})()},[b,t,n,r,s,u,l]);const Q=e.useMemo(()=>{const e=Ft(s),t=c&&Object.keys(c).length>0?c:{routerAddress:e?.routerAddress||"0x0000000000000000000000000000000000000000",bitzyQueryAddress:e?.bitzyQueryAddress||"0x0000000000000000000000000000000000000000",wrappedAddress:e?.wrappedAddress||"0x0000000000000000000000000000000000000000",nativeAddress:e?.nativeAddress||"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"},n=Wt.getInstance({baseUrl:u,timeout:f,headers:d});return new on({config:t,defaultPartCount:l,apiClient:n,publicClient:p})},[c,l,u,f,d,p,s]),Y=e.useCallback(()=>{V(null)},[]),q=e.useCallback(async()=>{if(!t||!n||!r||"0"===r)return I(new w(0)),P([]),B([]),S([]),$([]),U(!1),k(!1),void V(null);D(!0),V(null);try{const e={amountIn:r,srcToken:t,dstToken:n,chainId:s,partCount:G,types:A,enabledSources:v},i=await Q.fetchRoute(e);I(i.amountOutBN),P(i.routes),B(i.distributions),S(i.amountOutRoutes),$(i.amountInParts),U(i.isAmountOutError),_(i.isWrap),k(!0)}catch(e){const t=e instanceof Error?e.message:"Unknown error occurred";V(t),console.error("Error fetching route:",e),I(new w(0)),P([]),B([]),S([]),$([]),U(!0),k(!1)}finally{D(!1)}},[Q,t,n,r,s,G,A,v]),K=e.useMemo(()=>rn(q,300),[q]);return e.useEffect(()=>{if(!r||"0"===r)return I(new w(0)),P([]),B([]),S([]),$([]),U(!1),k(!1),void V(null);K();const e=setInterval(()=>{K()},h);return()=>{clearInterval(e),"function"==typeof K.cancel&&K.cancel()}},[r,t?.address,n?.address,K,h]),e.useEffect(()=>{F&&q()},[q,F,Q]),{routes:C,distributions:O,amountOutRoutes:N,amountOutBN:x,amountInParts:T,fetchRoute:q,isLoading:R,isAmountOutError:z,isFirstFetch:F,isWrap:L,error:M,clearError:Y}};exports.APIClient=Wt,exports.API_ENDPOINTS=Vt,exports.BITZY_QUERY_ABI=sn,exports.CONTRACT_ADDRESSES=Ut,exports.DEFAULT_NETWORKS=kt,exports.DEFAULT_PART_COUNT=Rt,exports.DEFAULT_TIMEOUT=3e4,exports.DEX_INTERFACE=St,exports.DEX_ROUTER=Mt,exports.DEX_ROUTERS=zt,exports.ERROR_CODES=jt,exports.HIGH_VALUE_TOKENS=Qt,exports.LIQUIDITY_SOURCES=Lt,exports.ROUTER_TARGET=$t,exports.SwapV3Service=on,exports.USER_TARGET=Tt,exports.calculatePartCount=function(e,t,n=10){return new w(e).times(t).lt(1)?1:n},exports.calculatePriceImpact=Xt,exports.clearMinimumAmountsCache=function(){Gt=null,console.log("Minimum amounts cache cleared")},exports.debounce=rn,exports.ensureBigNumber=e=>e instanceof w?e:new w(e),exports.fetchBatchSwapRoutes=async function(e){return(await Promise.allSettled(e.map(async({options:e,config:t})=>{try{return{success:!0,data:await an(e,t)}}catch(e){return{success:!1,error:e instanceof Error?e.message:"Unknown error"}}}))).map(e=>"fulfilled"===e.status?e.value:{success:!1,error:e.reason?.message||"Unknown error"})},exports.fetchSwapRoute=an,exports.fetchSwapRouteSimple=async function(e,t={}){const{types:n,enabledSources:r}=_t(e.chainId);return an({...e,types:n,enabledSources:r},{...t,forcePartCount:t.forcePartCount})},exports.formatError=function(e){return"string"==typeof e?e:e?.message?e.message:e?.error?e.error:"Unknown error occurred"},exports.fromTokenAmount=Zt,exports.getContractAddresses=Ft,exports.getDexRouters=e=>zt[e]||{},exports.getLiquiditySources=_t,exports.getOptimalPartCount=function(e,t,n=5){return Xt(e,t,5)>n?1:5},exports.getPartCountOffline=qt,exports.getPartCountOnline=Kt,exports.getPartCountWithFallback=Ht,exports.getSwapQuote=async function(e,t,n,r,s={}){const i=await an({amountIn:n,srcToken:e,dstToken:t,chainId:r},s);return{amountOut:i.amountOutBN.toFixed(0),routes:i.routes.length}},exports.getSwapRoute=an,exports.isBigNumber=e=>e instanceof w,exports.isHighValueToken=Yt,exports.isNativeToken=Jt,exports.isWrappedToken=en,exports.toTokenAmount=function(e,t){return new w(e).dividedBy(new w(10).pow(t)).toString()},exports.useSwapRoutes=un,exports.useSwapV3Routes=un,exports.validateAmount=nn,exports.validateTokens=tn;
2
4
  //# sourceMappingURL=index.js.map