@bitzy-app/bitzy-sdk 0.0.7 → 0.1.2

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,4 +1,2 @@
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;
1
+ "use strict";var e=require("bignumber.js"),t=require("viem"),r=require("react");class s extends Error{constructor(e){super(e.message),this.name="SwapError",this.code=e.code,this.details=e.details,Error.captureStackTrace&&Error.captureStackTrace(this,s)}}const n={V2:0,V3:1},o="0x0000000000000000000000000000000000000001",a="0x0000000000000000000000000000000000000000",i=5,u="https://api-public.bitzy.app",c={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)}},l={3637:{rpcUrls:["https://rpc.botanixlabs.com"],name:"Botanix Mainnet",nativeCurrency:{name:"Bitcoin",symbol:"BTC",decimals:18}},3636:{rpcUrls:["https://node.botanixlabs.dev"],name:"Botanix Testnet",nativeCurrency:{name:"Bitcoin",symbol:"BTC",decimals:18}}},p={3637:{types:[1,2],enabledSources:[1]},3636:{types:[1,2],enabledSources:[1]}},f=e=>p[e]||{types:[1,2],enabledSources:[1]},E=e=>d[e],m=d,A=c[3637]||{},C={PATH_V3:"/api/sdk/bestpath/split",ASSET_MINIMUM:"/api/sdk/asset/minimum"},g={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 y{constructor(e){this.config=e}static getInstance(e){if(!y.instance){const t={...e,headers:{...process.env.NEXT_PUBLIC_BITZY_API_KEY&&{"authen-key":process.env.NEXT_PUBLIC_BITZY_API_KEY},...e.headers}};y.instance=new y(t)}return y.instance}static resetInstance(){y.instance=null}async request(e,t={}){const r=new AbortController,n=setTimeout(()=>r.abort(),this.config.timeout);try{const s=await fetch(`${this.config.baseUrl}${e}`,{...t,signal:r.signal,headers:{"Content-Type":"application/json",...this.config.headers,...t.headers}});if(clearTimeout(n),!s.ok)throw new Error(`HTTP ${s.status}: ${s.statusText}`);return await s.json()}catch(t){if(clearTimeout(n),t instanceof Error){if("AbortError"===t.name)throw new s({message:"Request timeout",code:g.API_ERROR,details:{endpoint:e,timeout:this.config.timeout}});throw new s({message:t.message,code:g.API_ERROR,details:{endpoint:e,originalError:t}})}throw new s({message:"Unknown API error",code:g.API_ERROR,details:{endpoint:e,originalError:t}})}}async getPathV3(e,t,r,s,n){const o=new URLSearchParams;return o.set("src",e.address),o.set("dest",t.address),o.set("amount",r),o.set("typeId",JSON.stringify(s)),o.set("sourceId",JSON.stringify(n)),this.request(`${C.PATH_V3}?${o.toString()}`,{method:"GET"})}async getAssetMinimum(){return this.request(C.ASSET_MINIMUM,{method:"GET"})}}y.instance=null;let b=null;const h={3637:["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE","0x0D2437F93Fed6EA64Ef01cCde385FB1263910C56","0x29eE6138DD4C9815f46D34a4A1ed48F46758A402","0x9BC574a6f1170e90D80826D86a6126d59198A3Ef","0xA0b86a33E6441b8c4C8C0C4C0C4C0C4C0C4C0C4C","0xdAC17F958D2ee523a2206206994597C13D831ec7"],3636:["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE","0x233631132FD56c8f86D1FC97F0b82420a8d20af3","0xA0b86a33E6441b8c4C8C0C4C0C4C0C4C0C4C0C4C","0xdAC17F958D2ee523a2206206994597C13D831ec7"]};function w(e,t){if(!e?.address)return!1;const r=h[t];return!!r&&r.some(t=>t.toLowerCase()===e.address.toLowerCase())}function x(e,t,r,s=5){const n=w(e,r),o=w(t,r);return n&&o?s:1}async function T(t,r,s,n,o,a,i=5){try{console.log("Fetching online partCount data...");const u=await async function(e,t){const r=Date.now();if(b&&r<b.expiresAt)return console.log("Using cached minimum amounts data"),b.data;console.log("Fetching fresh minimum amounts data from API");const s=y.getInstance({baseUrl:e,timeout:5e3,headers:{...t&&{"authen-key":t}}}),n=await s.getAssetMinimum();if(!n.success)throw new Error(`API request failed: ${n.error||"Unknown error"}`);return b={data:n.data||[],timestamp:r,expiresAt:r+3e5},b.data}(o,a),c=u.find(e=>e.token?.toLowerCase()===t.address.toLowerCase()),d=u.find(e=>e.token?.toLowerCase()===r.address.toLowerCase()),l=new e(s);return c&&d&&l.gte(c.minimumAmount)&&l.gte(d.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"),x(t,r,n,i))}catch(e){return console.warn("Failed to fetch online partCount data:",e),console.log("Falling back to offline partCount logic"),x(t,r,n,i)}}async function I(e,t,r,s,n,o=5,a){try{return await T(e,t,r,s,n,a,o)}catch(e){return console.warn("Online partCount failed, using offline fallback:",e),o}}function D(e,t,r){if(0===t)return 1/0;return e/r/t*100}function O(t,r){return!t||isNaN(Number(t))?new e(0):new e(t).times(new e(10).pow(r))}function R(e,t){return e.address.toLowerCase()===t.toLowerCase()}function B(e,t){return e.address.toLowerCase()===t.toLowerCase()}function S(e,t){return e&&t&&e.address&&t.address&&e.address!==t.address&&e.chainId===t.chainId}function P(t){if(!t||isNaN(Number(t)))return!1;const r=new e(t);return r.gt(0)&&r.isFinite()}function F(e,t){let r;const s=(...s)=>{clearTimeout(r),r=setTimeout(()=>e(...s),t)};return s.cancel=()=>{clearTimeout(r)},s}const N=[{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 _{constructor(e){this.config=e}getPublicClient(e){if(this.config.publicClient)return this.config.publicClient;const r=(e=>l[e])(e);if(!r)throw new s({message:`Unsupported chainId: ${e}`,code:g.NETWORK_NOT_SUPPORTED,details:{chainId:e}});const n=t.defineChain({id:e,name:r.name,network:r.name.toLowerCase().replace(/\s+/g,"-"),nativeCurrency:r.nativeCurrency,rpcUrls:{default:{http:r.rpcUrls},public:{http:r.rpcUrls}}});return t.createPublicClient({chain:n,transport:t.http()})}async fetchRoute(r){const{amountIn:i,srcToken:u,dstToken:c,chainId:d,partCount:l,forcePartCount:p}=r,f=p||l||this.getPartCount(u,c,d,this.config.defaultPartCount);if(!S(u,c))throw new s({message:"Invalid tokens provided",code:g.INVALID_TOKENS,details:{srcToken:u,dstToken:c}});if(!P(i))throw new s({message:"Invalid amount provided",code:g.INVALID_AMOUNT,details:{amountIn:i}});const E=O(i,u.decimals),{routerAddress:m,bitzyQueryAddress:C,wrappedAddress:y,nativeAddress:b}=this.config.config,h=R(u,b),w=R(c,b);if(h&&B(c,y)||w&&B(u,y)){const e=h?"wrap":"unwrap",r=E;return{routes:[[{routerAddress:m,lpAddress:t.zeroAddress,fromToken:u.address,toToken:c.address,from:u.address,to:c.address,part:"100000000",amountAfterFee:"10000",dexInterface:0}]],distributions:[f],amountOutRoutes:[r],amountOutBN:r,amountInParts:[E],isAmountOutError:!1,isWrap:e}}const x=h?{...u,address:y}:u,T=w?{...c,address:y}:c;try{const s=await this.config.apiClient.getPathV3(x,T,E.toFixed(0),r.types||[1,2],r.enabledSources||[1]),{hops:i,validPath:u}=s.data;if(0===i.length)return{routes:[],distributions:[],amountOutRoutes:[],amountOutBN:new e(0),amountInParts:[],isAmountOutError:!0};const c=t.encodeAbiParameters([{type:"tuple[][]",components:[{type:"address",name:"src"},{type:"address",name:"dest"},{type:"uint8",name:"typeId"},{type:"uint8",name:"sourceId"},{type:"bytes",name:"path"}]}],[i]);let l=new e(0),p=[],m=[];const g=this.getPublicClient(d);try{const r=t.encodeFunctionData({abi:N,functionName:"splitQuery",args:[E.toFixed(0),c,f]}),s=await g.call({to:C,data:r,gas:50000000000n,gasPrice:void 0});if(s.data){const r=t.decodeFunctionResult({abi:N,functionName:"splitQuery",data:s.data})[1];if(r&&r.amountOut){l=new e(r.amountOut.toString());let s=r.distribution.map(t=>new e(t.toString()).toNumber());m=u.reduce((r,i,u)=>(s[u]>0&&r.push(i.map((r,s,i)=>({routerAddress:A[r.source+"_"+r.type]||t.zeroAddress,lpAddress:r.pool||t.zeroAddress,fromToken:r.src,toToken:r.dest,from:s>0||"V3"===r.type||r.src===y.toLowerCase()?a:o,to:s<i.length-1||s===i.length-1&&r.dest===y.toLowerCase()?a:o,part:"100000000",amountAfterFee:new e(1e4).minus(new e(r.fee||0).dividedBy(100)).toFixed(),dexInterface:n[r.type]||0}))),r),[]),p=s.filter(e=>e>0)}}}catch(t){l=new e(0),p=[],m=[]}const b=p.map(t=>l.times(t).dividedBy(f).dp(0,e.ROUND_DOWN)),h=p.map(t=>E.times(t).dividedBy(f).dp(0,e.ROUND_DOWN));return{routes:m,distributions:p,amountOutRoutes:b,amountOutBN:l,amountInParts:h,isAmountOutError:!1}}catch(e){throw new s({message:"Failed to fetch swap route",code:g.API_ERROR,details:{originalError:e,options:r}})}}getSupportedNetworks(){return Object.keys(m).map(Number)}getNetworkConfig(e){return this.config.config}getPartCount(e,t,r,s){return x(e,t,r,s)}}async function U(e,t={}){const{apiBaseUrl:r=u,defaultPartCount:s=i,timeout:n=3e4,headers:o={},publicClient:a}=t,c=e.chainId,d=E(c);if(!d)throw new Error(`Unsupported network: ${c}`);const l=y.getInstance({baseUrl:r,timeout:n,headers:o});return new _({config:{routerAddress:d.routerAddress,bitzyQueryAddress:d.bitzyQueryAddress,wrappedAddress:d.wrappedAddress,nativeAddress:d.nativeAddress},defaultPartCount:s,apiClient:l,publicClient:a}).fetchRoute(e)}const k=(s,n,o,a,i={})=>{const c=r.useMemo(()=>({}),[]),d=r.useMemo(()=>({routerAddress:t.zeroAddress,bitzyQueryAddress:t.zeroAddress,wrappedAddress:t.zeroAddress,nativeAddress:t.zeroAddress}),[]),{apiBaseUrl:l,addressConfig:p,defaultPartCount:m,timeout:A,headers:C,refreshInterval:g,publicClient:b,configTypes:h,configEnabledSources:w,forcePartCount:T,useOnlinePartCount:D}=r.useMemo(()=>{const{apiBaseUrl:e=u,config:t=d,defaultPartCount:r=5,timeout:s=3e4,headers:n=c,refreshInterval:o=1e4,publicClient:a,types:l,enabledSources:p,forcePartCount:f,useOnlinePartCount:E=!1}=i;return{apiBaseUrl:e,addressConfig:t,defaultPartCount:r,timeout:s,headers:n,refreshInterval:o,publicClient:a,configTypes:l,configEnabledSources:p,forcePartCount:f,useOnlinePartCount:E}},[i,c,d]),O=r.useMemo(()=>f(a),[a]),R=r.useMemo(()=>h??O.types,[h,O.types]),B=r.useMemo(()=>w??O.enabledSources,[w,O.enabledSources]);r.useEffect(()=>{console.log("config",i)},[i]),r.useEffect(()=>{console.log("srcToken",s)},[s]),r.useEffect(()=>{console.log("dstToken",n)},[n]),r.useEffect(()=>{console.log("amountIn",o)},[o]),r.useEffect(()=>{console.log("chainId",a)},[a]),r.useEffect(()=>{console.log("apiBaseUrl",l)},[l]),r.useEffect(()=>{console.log("addressConfig",p)},[p]),r.useEffect(()=>{console.log("defaultPartCount",m)},[m]),r.useEffect(()=>{console.log("timeout",A)},[A]),r.useEffect(()=>{console.log("headers",C)},[C]),r.useEffect(()=>{console.log("types",R)},[R]),r.useEffect(()=>{console.log("enabledSources",B)},[B]);const[S,P]=r.useState(new e(0)),[N,U]=r.useState([]),[k,v]=r.useState([]),[L,M]=r.useState([]),[V,Q]=r.useState([]),[z,Y]=r.useState(!1),[W,K]=r.useState(!1),[q,$]=r.useState(),[H,G]=r.useState(!1),[Z,j]=r.useState(null),[X,J]=r.useState(null),ee=r.useMemo(()=>(console.log("partCount",0,D),D?null!==X?X:x(s,n,a,m):(console.log("partCount",1,T),void 0!==T?T:(console.log("partCount",2,m),x(s,n,a,m)))),[m,T,D,X,s,n,a]);r.useEffect(()=>{if(!(D&&s&&n&&o))return void J(null);(async()=>{try{const e=await I(s,n,o,a,l,m);J(e)}catch(e){console.warn("Failed to fetch online partCount:",e),J(null)}})()},[D,s,n,o,a,l,m]);const te=r.useMemo(()=>{const e=E(a),t=p&&Object.keys(p).length>0?p:{routerAddress:e?.routerAddress||"0x0000000000000000000000000000000000000000",bitzyQueryAddress:e?.bitzyQueryAddress||"0x0000000000000000000000000000000000000000",wrappedAddress:e?.wrappedAddress||"0x0000000000000000000000000000000000000000",nativeAddress:e?.nativeAddress||"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"},r=y.getInstance({baseUrl:l,timeout:A,headers:C});return new _({config:t,defaultPartCount:m,apiClient:r,publicClient:b})},[p,m,l,A,C,b,a]),re=r.useCallback(()=>{j(null)},[]),se=r.useCallback(async()=>{if(!s||!n||!o||"0"===o)return P(new e(0)),U([]),v([]),M([]),Q([]),K(!1),G(!1),void j(null);Y(!0),j(null);try{const e={amountIn:o,srcToken:s,dstToken:n,chainId:a,partCount:ee,types:R,enabledSources:B},t=await te.fetchRoute(e);P(t.amountOutBN),U(t.routes),v(t.distributions),M(t.amountOutRoutes),Q(t.amountInParts),K(t.isAmountOutError),$(t.isWrap),G(!0)}catch(t){const r=t instanceof Error?t.message:"Unknown error occurred";j(r),console.error("Error fetching route:",t),P(new e(0)),U([]),v([]),M([]),Q([]),K(!0),G(!1)}finally{Y(!1)}},[te,s,n,o,a,ee,R,B]),ne=r.useMemo(()=>F(se,300),[se]);return r.useEffect(()=>{if(!o||"0"===o)return P(new e(0)),U([]),v([]),M([]),Q([]),K(!1),G(!1),void j(null);ne();const t=setInterval(()=>{ne()},g);return()=>{clearInterval(t),"function"==typeof ne.cancel&&ne.cancel()}},[o,s?.address,n?.address,ne,g]),r.useEffect(()=>{H&&se()},[se,H,te]),{routes:N,distributions:k,amountOutRoutes:L,amountOutBN:S,amountInParts:V,fetchRoute:se,isLoading:z,isAmountOutError:W,isFirstFetch:H,isWrap:q,error:Z,clearError:re}};exports.APIClient=y,exports.API_ENDPOINTS=C,exports.BITZY_QUERY_ABI=N,exports.CONTRACT_ADDRESSES=d,exports.DEFAULT_NETWORKS=m,exports.DEFAULT_PART_COUNT=i,exports.DEFAULT_TIMEOUT=3e4,exports.DEX_INTERFACE=n,exports.DEX_ROUTER=A,exports.DEX_ROUTERS=c,exports.ERROR_CODES=g,exports.HIGH_VALUE_TOKENS=h,exports.LIQUIDITY_SOURCES=p,exports.ROUTER_TARGET=a,exports.SwapV3Service=_,exports.USER_TARGET=o,exports.calculatePartCount=function(t,r,s=10){return new e(t).times(r).lt(1)?1:s},exports.calculatePriceImpact=D,exports.clearMinimumAmountsCache=function(){b=null,console.log("Minimum amounts cache cleared")},exports.debounce=F,exports.ensureBigNumber=t=>t instanceof e?t:new e(t),exports.fetchBatchSwapRoutes=async function(e){return(await Promise.allSettled(e.map(async({options:e,config:t})=>{try{return{success:!0,data:await U(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=U,exports.fetchSwapRouteSimple=async function(e,t={}){const{types:r,enabledSources:s}=f(e.chainId);return U({...e,types:r,enabledSources:s},{...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=O,exports.getContractAddresses=E,exports.getDexRouters=e=>c[e]||{},exports.getLiquiditySources=f,exports.getOptimalPartCount=function(e,t,r=5){return D(e,t,5)>r?1:5},exports.getPartCountOffline=x,exports.getPartCountOnline=T,exports.getPartCountWithFallback=I,exports.getSwapQuote=async function(e,t,r,s,n={}){const o=await U({amountIn:r,srcToken:e,dstToken:t,chainId:s},n);return{amountOut:o.amountOutBN.toFixed(0),routes:o.routes.length}},exports.getSwapRoute=U,exports.isBigNumber=t=>t instanceof e,exports.isHighValueToken=w,exports.isNativeToken=R,exports.isWrappedToken=B,exports.toTokenAmount=function(t,r){return new e(t).dividedBy(new e(10).pow(r)).toString()},exports.useSwapRoutes=k,exports.useSwapV3Routes=k,exports.validateAmount=P,exports.validateTokens=S;
4
2
  //# sourceMappingURL=index.js.map