@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.esm.js +3 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -8
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import{zeroAddress as e,encodeAbiParameters as t,encodeFunctionData as n,decodeFunctionResult as r}from"viem";import{useMemo as o,useEffect as s,useState as i,useCallback as a}from"react";var u=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,c=Math.ceil,l=Math.floor,f="[BigNumber Error] ",d=f+"Number primitive has more than 15 significant digits: ",p=1e14,h=14,g=9007199254740991,m=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],E=1e7,A=1e9;function w(e){var t=0|e;return e>0||e===t?t:t-1}function y(e){for(var t,n,r=1,o=e.length,s=e[0]+"";r<o;){for(t=e[r++]+"",n=h-t.length;n--;t="0"+t);s+=t}for(o=s.length;48===s.charCodeAt(--o););return s.slice(0,o+1||1)}function b(e,t){var n,r,o=e.c,s=t.c,i=e.s,a=t.s,u=e.e,c=t.e;if(!i||!a)return null;if(n=o&&!o[0],r=s&&!s[0],n||r)return n?r?0:-a:i;if(i!=a)return i;if(n=i<0,r=u==c,!o||!s)return r?0:!o^n?1:-1;if(!r)return u>c^n?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]^n?1:-1;return u==c?0:u>c^n?1:-1}function C(e,t,n,r){if(e<t||e>n||e!==l(e))throw Error(f+(r||"Argument")+("number"==typeof e?e<t||e>n?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function O(e){var t=e.c.length-1;return w(e.e/h)==t&&e.c[t]%2!=0}function I(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function v(e,t,n){var r,o;if(t<0){for(o=n+".";++t;o+=n);e=o+e}else if(++t>(r=e.length)){for(o=n,t-=r;--t;o+=n);e+=o}else t<r&&(e=e.slice(0,t)+"."+e.slice(t));return e}var N=function e(t){var n,r,o,s,i,a,N,D,T,B,x=$.prototype={constructor:$,toString:null,valueOf:null},P=new $(1),S=20,R=4,F=-7,_=21,U=-1e7,k=1e7,L=!1,M=1,V=0,Q={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},z="0123456789abcdefghijklmnopqrstuvwxyz",G=!0;function $(e,t){var n,s,i,a,c,f,p,m,E=this;if(!(E instanceof $))return new $(e,t);if(null==t){if(e&&!0===e._isBigNumber)return E.s=e.s,void(!e.c||e.e>k?E.c=E.e=null:e.e<U?E.c=[E.e=0]:(E.e=e.e,E.c=e.c.slice()));if((f="number"==typeof e)&&0*e==0){if(E.s=1/e<0?(e=-e,-1):1,e===~~e){for(a=0,c=e;c>=10;c/=10,a++);return void(a>k?E.c=E.e=null:(E.e=a,E.c=[e]))}m=String(e)}else{if(!u.test(m=String(e)))return o(E,m,f);E.s=45==m.charCodeAt(0)?(m=m.slice(1),-1):1}(a=m.indexOf("."))>-1&&(m=m.replace(".","")),(c=m.search(/e/i))>0?(a<0&&(a=c),a+=+m.slice(c+1),m=m.substring(0,c)):a<0&&(a=m.length)}else{if(C(t,2,z.length,"Base"),10==t&&G)return Y(E=new $(e),S+E.e+1,R);if(m=String(e),f="number"==typeof e){if(0*e!=0)return o(E,m,f,t);if(E.s=1/e<0?(m=m.slice(1),-1):1,$.DEBUG&&m.replace(/^0\.0*|\./,"").length>15)throw Error(d+e)}else E.s=45===m.charCodeAt(0)?(m=m.slice(1),-1):1;for(n=z.slice(0,t),a=c=0,p=m.length;c<p;c++)if(n.indexOf(s=m.charAt(c))<0){if("."==s){if(c>a){a=p;continue}}else if(!i&&(m==m.toUpperCase()&&(m=m.toLowerCase())||m==m.toLowerCase()&&(m=m.toUpperCase()))){i=!0,c=-1,a=0;continue}return o(E,String(e),f,t)}f=!1,(a=(m=r(m,t,10,E.s)).indexOf("."))>-1?m=m.replace(".",""):a=m.length}for(c=0;48===m.charCodeAt(c);c++);for(p=m.length;48===m.charCodeAt(--p););if(m=m.slice(c,++p)){if(p-=c,f&&$.DEBUG&&p>15&&(e>g||e!==l(e)))throw Error(d+E.s*e);if((a=a-c-1)>k)E.c=E.e=null;else if(a<U)E.c=[E.e=0];else{if(E.e=a,E.c=[],c=(a+1)%h,a<0&&(c+=h),c<p){for(c&&E.c.push(+m.slice(0,c)),p-=h;c<p;)E.c.push(+m.slice(c,c+=h));c=h-(m=m.slice(c)).length}else c-=p;for(;c--;m+="0");E.c.push(+m)}}else E.c=[E.e=0]}function j(e,t,n,r){var o,s,i,a,u;if(null==n?n=R:C(n,0,8),!e.c)return e.toString();if(o=e.c[0],i=e.e,null==t)u=y(e.c),u=1==r||2==r&&(i<=F||i>=_)?I(u,i):v(u,i,"0");else if(s=(e=Y(new $(e),t,n)).e,a=(u=y(e.c)).length,1==r||2==r&&(t<=s||s<=F)){for(;a<t;u+="0",a++);u=I(u,s)}else if(t-=i+(2===r&&s>i),u=v(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 q(e,t){for(var n,r,o=1,s=new $(e[0]);o<e.length;o++)(!(r=new $(e[o])).s||(n=b(s,r))===t||0===n&&s.s===t)&&(s=r);return s}function K(e,t,n){for(var r=1,o=t.length;!t[--o];t.pop());for(o=t[0];o>=10;o/=10,r++);return(n=r+n*h-1)>k?e.c=e.e=null:n<U?e.c=[e.e=0]:(e.e=n,e.c=t),e}function Y(e,t,n,r){var o,s,i,a,u,f,d,g=e.c,E=m;if(g){e:{for(o=1,a=g[0];a>=10;a/=10,o++);if((s=t-o)<0)s+=h,i=t,u=g[f=0],d=l(u/E[o-i-1]%10);else if((f=c((s+1)/h))>=g.length){if(!r)break e;for(;g.length<=f;g.push(0));u=d=0,o=1,i=(s%=h)-h+1}else{for(u=a=g[f],o=1;a>=10;a/=10,o++);d=(i=(s%=h)-h+o)<0?0:l(u/E[o-i-1]%10)}if(r=r||t<0||null!=g[f+1]||(i<0?u:u%E[o-i-1]),r=n<4?(d||r)&&(0==n||n==(e.s<0?3:2)):d>5||5==d&&(4==n||r||6==n&&(s>0?i>0?u/E[o-i]:0:g[f-1])%10&1||n==(e.s<0?8:7)),t<1||!g[0])return g.length=0,r?(t-=e.e+1,g[0]=E[(h-t%h)%h],e.e=-t||0):g[0]=e.e=0,e;if(0==s?(g.length=f,a=1,f--):(g.length=f+1,a=E[h-s],g[f]=i>0?l(u/E[o-i]%E[i])*a:0),r)for(;;){if(0==f){for(s=1,i=g[0];i>=10;i/=10,s++);for(i=g[0]+=a,a=1;i>=10;i/=10,a++);s!=a&&(e.e++,g[0]==p&&(g[0]=1));break}if(g[f]+=a,g[f]!=p)break;g[f--]=0,a=1}for(s=g.length;0===g[--s];g.pop());}e.e>k?e.c=e.e=null:e.e<U&&(e.c=[e.e=0])}return e}function W(e){var t,n=e.e;return null===n?e.toString():(t=y(e.c),t=n<=F||n>=_?I(t,n):v(t,n,"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,n;if(null!=e){if("object"!=typeof e)throw Error(f+"Object expected: "+e);if(e.hasOwnProperty(t="DECIMAL_PLACES")&&(C(n=e[t],0,A,t),S=n),e.hasOwnProperty(t="ROUNDING_MODE")&&(C(n=e[t],0,8,t),R=n),e.hasOwnProperty(t="EXPONENTIAL_AT")&&((n=e[t])&&n.pop?(C(n[0],-A,0,t),C(n[1],0,A,t),F=n[0],_=n[1]):(C(n,-A,A,t),F=-(_=n<0?-n:n))),e.hasOwnProperty(t="RANGE"))if((n=e[t])&&n.pop)C(n[0],-A,-1,t),C(n[1],1,A,t),U=n[0],k=n[1];else{if(C(n,-A,A,t),!n)throw Error(f+t+" cannot be zero: "+n);U=-(k=n<0?-n:n)}if(e.hasOwnProperty(t="CRYPTO")){if((n=e[t])!==!!n)throw Error(f+t+" not true or false: "+n);if(n){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw L=!n,Error(f+"crypto unavailable");L=n}else L=n}if(e.hasOwnProperty(t="MODULO_MODE")&&(C(n=e[t],0,9,t),M=n),e.hasOwnProperty(t="POW_PRECISION")&&(C(n=e[t],0,A,t),V=n),e.hasOwnProperty(t="FORMAT")){if("object"!=typeof(n=e[t]))throw Error(f+t+" not an object: "+n);Q=n}if(e.hasOwnProperty(t="ALPHABET")){if("string"!=typeof(n=e[t])||/^.?$|[+\-.\s]|(.).*\1/.test(n))throw Error(f+t+" invalid: "+n);G="0123456789"==n.slice(0,10),z=n}}return{DECIMAL_PLACES:S,ROUNDING_MODE:R,EXPONENTIAL_AT:[F,_],RANGE:[U,k],CRYPTO:L,MODULO_MODE:M,POW_PRECISION:V,FORMAT:Q,ALPHABET:z}},$.isBigNumber=function(e){if(!e||!0!==e._isBigNumber)return!1;if(!$.DEBUG)return!0;var t,n,r=e.c,o=e.e,s=e.s;e:if("[object Array]"=={}.toString.call(r)){if((1===s||-1===s)&&o>=-A&&o<=A&&o===l(o)){if(0===r[0]){if(0===o&&1===r.length)return!0;break e}if((t=(o+1)%h)<1&&(t+=h),String(r[0]).length==t){for(t=0;t<r.length;t++)if((n=r[t])<0||n>=p||n!==l(n))break e;if(0!==n)return!0}}}else if(null===r&&null===o&&(null===s||1===s||-1===s))return!0;throw Error(f+"Invalid BigNumber: "+e)},$.maximum=$.max=function(){return q(arguments,-1)},$.minimum=$.min=function(){return q(arguments,1)},$.random=(s=9007199254740992,i=Math.random()*s&2097151?function(){return l(Math.random()*s)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(e){var t,n,r,o,s,a=0,u=[],d=new $(P);if(null==e?e=S:C(e,0,A),o=c(e/h),L)if(crypto.getRandomValues){for(t=crypto.getRandomValues(new Uint32Array(o*=2));a<o;)(s=131072*t[a]+(t[a+1]>>>11))>=9e15?(n=crypto.getRandomValues(new Uint32Array(2)),t[a]=n[0],t[a+1]=n[1]):(u.push(s%1e14),a+=2);a=o/2}else{if(!crypto.randomBytes)throw L=!1,Error(f+"crypto unavailable");for(t=crypto.randomBytes(o*=7);a<o;)(s=281474976710656*(31&t[a])+1099511627776*t[a+1]+4294967296*t[a+2]+16777216*t[a+3]+(t[a+4]<<16)+(t[a+5]<<8)+t[a+6])>=9e15?crypto.randomBytes(7).copy(t,a):(u.push(s%1e14),a+=7);a=o/7}if(!L)for(;a<o;)(s=i())<9e15&&(u[a++]=s%1e14);for(o=u[--a],e%=h,o&&e&&(s=m[h-e],u[a]=l(o/s)*s);0===u[a];u.pop(),a--);if(a<0)u=[r=0];else{for(r=-1;0===u[0];u.splice(0,1),r-=h);for(a=1,s=u[0];s>=10;s/=10,a++);a<h&&(r-=h-a)}return d.e=r,d.c=u,d}),$.sum=function(){for(var e=1,t=arguments,n=new $(t[0]);e<t.length;)n=n.plus(t[e++]);return n},r=function(){var e="0123456789";function t(e,t,n,r){for(var o,s,i=[0],a=0,u=e.length;a<u;){for(s=i.length;s--;i[s]*=t);for(i[0]+=r.indexOf(e.charAt(a++)),o=0;o<i.length;o++)i[o]>n-1&&(null==i[o+1]&&(i[o+1]=0),i[o+1]+=i[o]/n|0,i[o]%=n)}return i.reverse()}return function(r,o,s,i,a){var u,c,l,f,d,p,h,g,m=r.indexOf("."),E=S,A=R;for(m>=0&&(f=V,V=0,r=r.replace(".",""),p=(g=new $(o)).pow(r.length-m),V=f,g.c=t(v(y(p.c),p.e,"0"),10,s,e),g.e=g.c.length),l=f=(h=t(r,o,s,a?(u=z,e):(u=e,z))).length;0==h[--f];h.pop());if(!h[0])return u.charAt(0);if(m<0?--l:(p.c=h,p.e=l,p.s=i,h=(p=n(p,g,E,A,s)).c,d=p.r,l=p.e),m=h[c=l+E+1],f=s/2,d=d||c<0||null!=h[c+1],d=A<4?(null!=m||d)&&(0==A||A==(p.s<0?3:2)):m>f||m==f&&(4==A||d||6==A&&1&h[c-1]||A==(p.s<0?8:7)),c<1||!h[0])r=d?v(u.charAt(1),-E,u.charAt(0)):u.charAt(0);else{if(h.length=c,d)for(--s;++h[--c]>s;)h[c]=0,c||(++l,h=[1].concat(h));for(f=h.length;!h[--f];);for(m=0,r="";m<=f;r+=u.charAt(h[m++]));r=v(r,l,u.charAt(0))}return r}}(),n=function(){function e(e,t,n){var r,o,s,i,a=0,u=e.length,c=t%E,l=t/E|0;for(e=e.slice();u--;)a=((o=c*(s=e[u]%E)+(r=l*s+(i=e[u]/E|0)*c)%E*E+a)/n|0)+(r/E|0)+l*i,e[u]=o%n;return a&&(e=[a].concat(e)),e}function t(e,t,n,r){var o,s;if(n!=r)s=n>r?1:-1;else for(o=s=0;o<n;o++)if(e[o]!=t[o]){s=e[o]>t[o]?1:-1;break}return s}function n(e,t,n,r){for(var o=0;n--;)e[n]-=o,o=e[n]<t[n]?1:0,e[n]=o*r+e[n]-t[n];for(;!e[0]&&e.length>1;e.splice(0,1));}return function(r,o,s,i,a){var u,c,f,d,g,m,E,A,y,b,C,O,I,v,N,D,T,B=r.s==o.s?1:-1,x=r.c,P=o.c;if(!(x&&x[0]&&P&&P[0]))return new $(r.s&&o.s&&(x?!P||x[0]!=P[0]:P)?x&&0==x[0]||!P?0*B:B/0:NaN);for(y=(A=new $(B)).c=[],B=s+(c=r.e-o.e)+1,a||(a=p,c=w(r.e/h)-w(o.e/h),B=B/h|0),f=0;P[f]==(x[f]||0);f++);if(P[f]>(x[f]||0)&&c--,B<0)y.push(1),d=!0;else{for(v=x.length,D=P.length,f=0,B+=2,(g=l(a/(P[0]+1)))>1&&(P=e(P,g,a),x=e(x,g,a),D=P.length,v=x.length),I=D,C=(b=x.slice(0,D)).length;C<D;b[C++]=0);T=P.slice(),T=[0].concat(T),N=P[0],P[1]>=a/2&&N++;do{if(g=0,(u=t(P,b,D,C))<0){if(O=b[0],D!=C&&(O=O*a+(b[1]||0)),(g=l(O/N))>1)for(g>=a&&(g=a-1),E=(m=e(P,g,a)).length,C=b.length;1==t(m,b,E,C);)g--,n(m,D<E?T:P,E,a),E=m.length,u=1;else 0==g&&(u=g=1),E=(m=P.slice()).length;if(E<C&&(m=[0].concat(m)),n(b,m,C,a),C=b.length,-1==u)for(;t(P,b,D,C)<1;)g++,n(b,D<C?T:P,C,a),C=b.length}else 0===u&&(g++,b=[0]);y[f++]=g,b[0]?b[C++]=x[I]||0:(b=[x[I]],C=1)}while((I++<v||null!=b[0])&&B--);d=null!=b[0],y[0]||y.splice(0,1)}if(a==p){for(f=1,B=y[0];B>=10;B/=10,f++);Y(A,s+(A.e=f+c*h-1)+1,i,d)}else A.e=c,A.r=+d;return A}}(),a=/^(-?)0([xbo])(?=\w[\w.]*$)/i,N=/^([^.]+)\.$/,D=/^\.([^.]+)$/,T=/^-?(Infinity|NaN)$/,B=/^\s*\+(?=[\w.])|^\s+|\s+$/g,o=function(e,t,n,r){var o,s=n?t:t.replace(B,"");if(T.test(s))e.s=isNaN(s)?null:s<0?-1:1;else{if(!n&&(s=s.replace(a,function(e,t,n){return o="x"==(n=n.toLowerCase())?16:"b"==n?2:8,r&&r!=o?e:t}),r&&(o=r,s=s.replace(N,"$1").replace(D,"0.$1")),t!=s))return new $(s,o);if($.DEBUG)throw Error(f+"Not a"+(r?" base "+r:"")+" number: "+t);e.s=null}e.c=e.e=null},x.absoluteValue=x.abs=function(){var e=new $(this);return e.s<0&&(e.s=1),e},x.comparedTo=function(e,t){return b(this,new $(e,t))},x.decimalPlaces=x.dp=function(e,t){var n,r,o,s=this;if(null!=e)return C(e,0,A),null==t?t=R:C(t,0,8),Y(new $(s),e+s.e+1,t);if(!(n=s.c))return null;if(r=((o=n.length-1)-w(this.e/h))*h,o=n[o])for(;o%10==0;o/=10,r--);return r<0&&(r=0),r},x.dividedBy=x.div=function(e,t){return n(this,new $(e,t),S,R)},x.dividedToIntegerBy=x.idiv=function(e,t){return n(this,new $(e,t),0,1)},x.exponentiatedBy=x.pow=function(e,t){var n,r,o,s,i,a,u,d,p=this;if((e=new $(e)).c&&!e.isInteger())throw Error(f+"Exponent not an integer: "+W(e));if(null!=t&&(t=new $(t)),i=e.e>14,!p.c||!p.c[0]||1==p.c[0]&&!p.e&&1==p.c.length||!e.c||!e.c[0])return d=new $(Math.pow(+W(p),i?e.s*(2-O(e)):+W(e))),t?d.mod(t):d;if(a=e.s<0,t){if(t.c?!t.c[0]:!t.s)return new $(NaN);(r=!a&&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||i&&p.c[1]>=24e7:p.c[0]<8e13||i&&p.c[0]<=9999975e7)))return s=p.s<0&&O(e)?-0:0,p.e>-1&&(s=1/s),new $(a?1/s:s);V&&(s=c(V/h+2))}for(i?(n=new $(.5),a&&(e.s=1),u=O(e)):u=(o=Math.abs(+W(e)))%2,d=new $(P);;){if(u){if(!(d=d.times(p)).c)break;s?d.c.length>s&&(d.c.length=s):r&&(d=d.mod(t))}if(o){if(0===(o=l(o/2)))break;u=o%2}else if(Y(e=e.times(n),e.e+1,1),e.e>14)u=O(e);else{if(0===(o=+W(e)))break;u=o%2}p=p.times(p),s?p.c&&p.c.length>s&&(p.c.length=s):r&&(p=p.mod(t))}return r?d:(a&&(d=P.div(d)),t?d.mod(t):s?Y(d,V,R,undefined):d)},x.integerValue=function(e){var t=new $(this);return null==e?e=R:C(e,0,8),Y(t,t.e+1,e)},x.isEqualTo=x.eq=function(e,t){return 0===b(this,new $(e,t))},x.isFinite=function(){return!!this.c},x.isGreaterThan=x.gt=function(e,t){return b(this,new $(e,t))>0},x.isGreaterThanOrEqualTo=x.gte=function(e,t){return 1===(t=b(this,new $(e,t)))||0===t},x.isInteger=function(){return!!this.c&&w(this.e/h)>this.c.length-2},x.isLessThan=x.lt=function(e,t){return b(this,new $(e,t))<0},x.isLessThanOrEqualTo=x.lte=function(e,t){return-1===(t=b(this,new $(e,t)))||0===t},x.isNaN=function(){return!this.s},x.isNegative=function(){return this.s<0},x.isPositive=function(){return this.s>0},x.isZero=function(){return!!this.c&&0==this.c[0]},x.minus=function(e,t){var n,r,o,s,i=this,a=i.s;if(t=(e=new $(e,t)).s,!a||!t)return new $(NaN);if(a!=t)return e.s=-t,i.plus(e);var u=i.e/h,c=e.e/h,l=i.c,f=e.c;if(!u||!c){if(!l||!f)return l?(e.s=-t,e):new $(f?i:NaN);if(!l[0]||!f[0])return f[0]?(e.s=-t,e):new $(l[0]?i:3==R?-0:0)}if(u=w(u),c=w(c),l=l.slice(),a=u-c){for((s=a<0)?(a=-a,o=l):(c=u,o=f),o.reverse(),t=a;t--;o.push(0));o.reverse()}else for(r=(s=(a=l.length)<(t=f.length))?a:t,a=t=0;t<r;t++)if(l[t]!=f[t]){s=l[t]<f[t];break}if(s&&(o=l,l=f,f=o,e.s=-e.s),(t=(r=f.length)-(n=l.length))>0)for(;t--;l[n++]=0);for(t=p-1;r>a;){if(l[--r]<f[r]){for(n=r;n&&!l[--n];l[n]=t);--l[n],l[r]+=p}l[r]-=f[r]}for(;0==l[0];l.splice(0,1),--c);return l[0]?K(e,l,c):(e.s=3==R?-1:1,e.c=[e.e=0],e)},x.modulo=x.mod=function(e,t){var r,o,s=this;return e=new $(e,t),!s.c||!e.s||e.c&&!e.c[0]?new $(NaN):!e.c||s.c&&!s.c[0]?new $(s):(9==M?(o=e.s,e.s=1,r=n(s,e,0,3),e.s=o,r.s*=o):r=n(s,e,0,M),(e=s.minus(r.times(e))).c[0]||1!=M||(e.s=s.s),e)},x.multipliedBy=x.times=function(e,t){var n,r,o,s,i,a,u,c,l,f,d,g,m,A,y,b=this,C=b.c,O=(e=new $(e,t)).c;if(!(C&&O&&C[0]&&O[0]))return!b.s||!e.s||C&&!C[0]&&!O||O&&!O[0]&&!C?e.c=e.e=e.s=null:(e.s*=b.s,C&&O?(e.c=[0],e.e=0):e.c=e.e=null),e;for(r=w(b.e/h)+w(e.e/h),e.s*=b.s,(u=C.length)<(f=O.length)&&(m=C,C=O,O=m,o=u,u=f,f=o),o=u+f,m=[];o--;m.push(0));for(A=p,y=E,o=f;--o>=0;){for(n=0,d=O[o]%y,g=O[o]/y|0,s=o+(i=u);s>o;)n=((c=d*(c=C[--i]%y)+(a=g*c+(l=C[i]/y|0)*d)%y*y+m[s]+n)/A|0)+(a/y|0)+g*l,m[s--]=c%A;m[s]=n}return n?++r:m.splice(0,1),K(e,m,r)},x.negated=function(){var e=new $(this);return e.s=-e.s||null,e},x.plus=function(e,t){var n,r=this,o=r.s;if(t=(e=new $(e,t)).s,!o||!t)return new $(NaN);if(o!=t)return e.s=-t,r.minus(e);var s=r.e/h,i=e.e/h,a=r.c,u=e.c;if(!s||!i){if(!a||!u)return new $(o/0);if(!a[0]||!u[0])return u[0]?e:new $(a[0]?r:0*o)}if(s=w(s),i=w(i),a=a.slice(),o=s-i){for(o>0?(i=s,n=u):(o=-o,n=a),n.reverse();o--;n.push(0));n.reverse()}for((o=a.length)-(t=u.length)<0&&(n=u,u=a,a=n,t=o),o=0;t;)o=(a[--t]=a[t]+u[t]+o)/p|0,a[t]=p===a[t]?0:a[t]%p;return o&&(a=[o].concat(a),++i),K(e,a,i)},x.precision=x.sd=function(e,t){var n,r,o,s=this;if(null!=e&&e!==!!e)return C(e,1,A),null==t?t=R:C(t,0,8),Y(new $(s),e,t);if(!(n=s.c))return null;if(r=(o=n.length-1)*h+1,o=n[o]){for(;o%10==0;o/=10,r--);for(o=n[0];o>=10;o/=10,r++);}return e&&s.e+1>r&&(r=s.e+1),r},x.shiftedBy=function(e){return C(e,-9007199254740991,g),this.times("1e"+e)},x.squareRoot=x.sqrt=function(){var e,t,r,o,s,i=this,a=i.c,u=i.s,c=i.e,l=S+4,f=new $("0.5");if(1!==u||!a||!a[0])return new $(!u||u<0&&(!a||a[0])?NaN:a?i:1/0);if(0==(u=Math.sqrt(+W(i)))||u==1/0?(((t=y(a)).length+c)%2==0&&(t+="0"),u=Math.sqrt(+t),c=w((c+1)/2)-(c<0||c%2),r=new $(t=u==1/0?"5e"+c:(t=u.toExponential()).slice(0,t.indexOf("e")+1)+c)):r=new $(u+""),r.c[0])for((u=(c=r.e)+l)<3&&(u=0);;)if(s=r,r=f.times(s.plus(n(i,s,l,1))),y(s.c).slice(0,u)===(t=y(r.c)).slice(0,u)){if(r.e<c&&--u,"9999"!=(t=t.slice(u-3,u+1))&&(o||"4999"!=t)){+t&&(+t.slice(1)||"5"!=t.charAt(0))||(Y(r,r.e+S+2,1),e=!r.times(r).eq(i));break}if(!o&&(Y(s,s.e+S+2,0),s.times(s).eq(i))){r=s;break}l+=4,u+=4,o=1}return Y(r,r.e+S+1,R,e)},x.toExponential=function(e,t){return null!=e&&(C(e,0,A),e++),j(this,e,t,1)},x.toFixed=function(e,t){return null!=e&&(C(e,0,A),e=e+this.e+1),j(this,e,t)},x.toFormat=function(e,t,n){var r,o=this;if(null==n)null!=e&&t&&"object"==typeof t?(n=t,t=null):e&&"object"==typeof e?(n=e,e=t=null):n=Q;else if("object"!=typeof n)throw Error(f+"Argument not an object: "+n);if(r=o.toFixed(e,t),o.c){var s,i=r.split("."),a=+n.groupSize,u=+n.secondaryGroupSize,c=n.groupSeparator||"",l=i[0],d=i[1],p=o.s<0,h=p?l.slice(1):l,g=h.length;if(u&&(s=a,a=u,u=s,g-=s),a>0&&g>0){for(s=g%a||a,l=h.substr(0,s);s<g;s+=a)l+=c+h.substr(s,a);u>0&&(l+=c+h.slice(s)),p&&(l="-"+l)}r=d?l+(n.decimalSeparator||"")+((u=+n.fractionGroupSize)?d.replace(new RegExp("\\d{"+u+"}\\B","g"),"$&"+(n.fractionGroupSeparator||"")):d):l}return(n.prefix||"")+r+(n.suffix||"")},x.toFraction=function(e){var t,r,o,s,i,a,u,c,l,d,p,g,E=this,A=E.c;if(null!=e&&(!(u=new $(e)).isInteger()&&(u.c||1!==u.s)||u.lt(P)))throw Error(f+"Argument "+(u.isInteger()?"out of range: ":"not an integer: ")+W(u));if(!A)return new $(E);for(t=new $(P),l=r=new $(P),o=c=new $(P),g=y(A),i=t.e=g.length-E.e-1,t.c[0]=m[(a=i%h)<0?h+a:a],e=!e||u.comparedTo(t)>0?i>0?t:l:u,a=k,k=1/0,u=new $(g),c.c[0]=0;d=n(u,t,0,1),1!=(s=r.plus(d.times(o))).comparedTo(e);)r=o,o=s,l=c.plus(d.times(s=l)),c=s,t=u.minus(d.times(s=t)),u=s;return s=n(e.minus(r),o,0,1),c=c.plus(s.times(l)),r=r.plus(s.times(o)),c.s=l.s=E.s,p=n(l,o,i*=2,R).minus(E).abs().comparedTo(n(c,r,i,R).minus(E).abs())<1?[l,o]:[c,r],k=a,p},x.toNumber=function(){return+W(this)},x.toPrecision=function(e,t){return null!=e&&C(e,1,A),j(this,e,t,2)},x.toString=function(e){var t,n=this,o=n.s,s=n.e;return null===s?o?(t="Infinity",o<0&&(t="-"+t)):t="NaN":(null==e?t=s<=F||s>=_?I(y(n.c),s):v(y(n.c),s,"0"):10===e&&G?t=v(y((n=Y(new $(n),S+s+1,R)).c),n.e,"0"):(C(e,2,z.length,"Base"),t=r(v(y(n.c),s,"0"),10,e,o,!0)),o<0&&n.c[0]&&(t="-"+t)),t},x.valueOf=x.toJSON=function(){return W(this)},x._isBigNumber=!0,x[Symbol.toStringTag]="BigNumber",x[Symbol.for("nodejs.util.inspect.custom")]=x.valueOf,null!=t&&$.set(t),$}();const D=e=>e instanceof N?e:new N(e),T=e=>e instanceof N;class B extends Error{constructor(e){super(e.message),this.name="SwapError",this.code=e.code,this.details=e.details,Error.captureStackTrace&&Error.captureStackTrace(this,B)}}const x={V2:0,V3:1},P="0x0000000000000000000000000000000000000001",S="0x0000000000000000000000000000000000000000",R=5,F=3e4,_="https://api-public.bitzy.app",U={3637:{BITZY_V3:"0xA5E0AE4e5103dc71cA290AA3654830442357A489",BITZY_V2:"0x07c49Ade88b40f1Ac05707f236d7706f834F6BDB",AVOCADO_V2:"0xA4B4cDeC4fE2839d3D3a49Ad5E20c21c01A31091"},3636:{BITZY_V3:"0xA5E0AE4e5103dc71cA290AA3654830442357A489",BITZY_V2:"0x07c49Ade88b40f1Ac05707f236d7706f834F6BDB",AVOCADO_V2:"0xA4B4cDeC4fE2839d3D3a49Ad5E20c21c01A31091"}},k={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:{types:[1,2],enabledSources:[1]},3636:{types:[1,2],enabledSources:[1]}},M=e=>L[e]||{types:[1,2],enabledSources:[1]},V=e=>k[e],Q=e=>U[e]||{},z=k,G=U[3637]||{},$={PATH_V3:"/api/sdk/bestpath/split",ASSET_MINIMUM:"/api/sdk/asset/minimum"},j={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 q{constructor(e){this.config=e}static getInstance(e){if(!q.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}};q.instance=new q(t)}return q.instance}static resetInstance(){q.instance=null}async request(e,t={}){const n=new AbortController,r=setTimeout(()=>n.abort(),this.config.timeout);try{const o=await fetch(`${this.config.baseUrl}${e}`,{...t,signal:n.signal,headers:{"Content-Type":"application/json",...this.config.headers,...t.headers}});if(clearTimeout(r),!o.ok)throw new Error(`HTTP ${o.status}: ${o.statusText}`);return await o.json()}catch(t){if(clearTimeout(r),t instanceof Error){if("AbortError"===t.name)throw new B({message:"Request timeout",code:j.API_ERROR,details:{endpoint:e,timeout:this.config.timeout}});throw new B({message:t.message,code:j.API_ERROR,details:{endpoint:e,originalError:t}})}throw new B({message:"Unknown API error",code:j.API_ERROR,details:{endpoint:e,originalError:t}})}}async getPathV3(e,t,n,r,o){const s={src:e.address,dest:t.address,amount:n,typeId:r,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,n)=>[...t,`${n}=${Array.isArray(e[n])?'["'+e[n].map(e=>e).join('","')+'"]':e[n]}`],[]).join("&")}}q.instance=null;let K=null;function Y(){K=null,console.log("Minimum amounts cache cleared")}const W={3637:["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE","0x0D2437F93Fed6EA64Ef01cCde385FB1263910C56","0x29eE6138DD4C9815f46D34a4A1ed48F46758A402","0x9BC574a6f1170e90D80826D86a6126d59198A3Ef","0xA0b86a33E6441b8c4C8C0C4C0C4C0C4C0C4C0C4C","0xdAC17F958D2ee523a2206206994597C13D831ec7"],3636:["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE","0x233631132FD56c8f86D1FC97F0b82420a8d20af3","0xA0b86a33E6441b8c4C8C0C4C0C4C0C4C0C4C0C4C","0xdAC17F958D2ee523a2206206994597C13D831ec7"]};function H(e,t){if(!e?.address)return!1;const n=W[t];return!!n&&n.some(t=>t.toLowerCase()===e.address.toLowerCase())}function Z(e,t,n,r=5){const o=H(e,n),s=H(t,n);return o&&s?r:1}async function X(e,t,n,r,o,s,i=5){try{console.log("Fetching online partCount data...");const a=await async function(e,t){const n=Date.now();if(K&&n<K.expiresAt)return console.log("Using cached minimum amounts data"),K.data;console.log("Fetching fresh minimum amounts data from API");const r=q.getInstance({baseUrl:e,timeout:5e3,headers:{...t&&{"authen-key":t}}}),o=await r.getAssetMinimum();if(!o.success)throw new Error(`API request failed: ${o.error||"Unknown error"}`);return K={data:o.data||[],timestamp:n,expiresAt:n+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 N(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"),Z(e,t,r,i))}catch(n){return console.warn("Failed to fetch online partCount data:",n),console.log("Falling back to offline partCount logic"),Z(e,t,r,i)}}async function J(e,t,n,r,o,s=5,i){try{return await X(e,t,n,r,o,i,s)}catch(e){return console.warn("Online partCount failed, using offline fallback:",e),s}}function ee(e,t,n){if(0===t)return 1/0;return e/n/t*100}function te(e,t,n=5){return ee(e,t,5)>n?1:5}function ne(e,t){return!e||isNaN(Number(e))?new N(0):new N(e).times(new N(10).pow(t))}function re(e,t){return new N(e).dividedBy(new N(10).pow(t)).toString()}function oe(e,t){return e.address.toLowerCase()===t.toLowerCase()}function se(e,t){return e.address.toLowerCase()===t.toLowerCase()}function ie(e,t){return e&&t&&e.address&&t.address&&e.address!==t.address&&e.chainId===t.chainId}function ae(e){if(!e||isNaN(Number(e)))return!1;const t=new N(e);return t.gt(0)&&t.isFinite()}function ue(e,t,n=10){return new N(e).times(t).lt(1)?1:n}function ce(e){return"string"==typeof e?e:e?.message?e.message:e?.error?e.error:"Unknown error occurred"}function le(e,t){let n;const r=(...r)=>{clearTimeout(n),n=setTimeout(()=>e(...r),t)};return r.cancel=()=>{clearTimeout(n)},r}const fe=[{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 de{constructor(e){this.config=e}async fetchRoute(o){const{amountIn:s,srcToken:i,dstToken:a,chainId:u,partCount:c,forcePartCount:l}=o,f=l||c||this.getPartCount(i,a,u,this.config.defaultPartCount);if(!ie(i,a))throw new B({message:"Invalid tokens provided",code:j.INVALID_TOKENS,details:{srcToken:i,dstToken:a}});if(!ae(s))throw new B({message:"Invalid amount provided",code:j.INVALID_AMOUNT,details:{amountIn:s}});const d=ne(s,i.decimals),{routerAddress:p,bitzyQueryAddress:h,wrappedAddress:g,nativeAddress:m}=this.config.config,E=oe(i,m),A=oe(a,m);if(E&&se(a,g)||A&&se(i,g)){const t=E?"wrap":"unwrap",n=d;return{routes:[[{routerAddress:p,lpAddress:e,fromToken:i.address,toToken:a.address,from:i.address,to:a.address,part:"100000000",amountAfterFee:"10000",dexInterface:0}]],distributions:[f],amountOutRoutes:[n],amountOutBN:n,amountInParts:[d],isAmountOutError:!1,isWrap:t}}const w=E?{...i,address:g}:i,y=A?{...a,address:g}:a;try{const s=await this.config.apiClient.getPathV3(w,y,d.toFixed(0),o.types||[1,2],o.enabledSources||[1]),{hops:i,validPath:a}=s.data;if(0===i.length)return console.log("SDK: No hops found"),{routes:[],distributions:[],amountOutRoutes:[],amountOutBN:new N(0),amountInParts:[],isAmountOutError:!0};console.log("SDK: hops.length =",i.length),console.log("SDK: validPath.length =",a.length),console.log("SDK: partCount =",f);const u=t([{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 c=new N(0),l=[],p=[];if(this.config.publicClient)try{console.log("SDK: Calling splitQuery with:",{bitzyQueryAddress:h,amountIn:d.toFixed(0),partCount:f,encodedRoutesLength:u.length});const t=n({abi:fe,functionName:"splitQuery",args:[d.toFixed(0),u,f]}),o=await this.config.publicClient.call({to:h,data:t,gas:50000000000n,gasPrice:void 0});if(console.log("SDK: Contract call result:",o),o.data){const t=r({abi:fe,functionName:"splitQuery",data:o.data})[1];if(t&&t.amountOut){c=new N(t.amountOut.toString());let n=t.distribution.map(e=>new N(e.toString()).toNumber());p=a.reduce((t,r,o)=>(n[o]>0&&t.push(r.map((t,n,r)=>({routerAddress:G[t.source+"_"+t.type]||e,lpAddress:t.pool||e,fromToken:t.src,toToken:t.dest,from:n>0||"V3"===t.type||t.src===g.toLowerCase()?S:P,to:n<r.length-1||n===r.length-1&&t.dest===g.toLowerCase()?S:P,part:"100000000",amountAfterFee:new N(1e4).minus(new N(t.fee||0).dividedBy(100)).toFixed(),dexInterface:x[t.type]||0}))),t),[]),l=n.filter(e=>e>0)}}}catch(e){console.error("SDK: splitQuery contract call failed:",e),c=new N(0),l=[],p=[]}else console.error("SDK: No publicClient available - this is the problem!"),c=new N(0),l=[],p=[];const m=l.map(e=>c.times(e).dividedBy(f).dp(0,N.ROUND_DOWN)),E=l.map(e=>d.times(e).dividedBy(f).dp(0,N.ROUND_DOWN));return{routes:p,distributions:l,amountOutRoutes:m,amountOutBN:c,amountInParts:E,isAmountOutError:!1}}catch(e){throw new B({message:"Failed to fetch swap route",code:j.API_ERROR,details:{originalError:e,options:o}})}}getSupportedNetworks(){return Object.keys(z).map(Number)}getNetworkConfig(e){return this.config.config}getPartCount(e,t,n,r){return Z(e,t,n,r)}}async function pe(e,t={}){const{apiBaseUrl:n=_,defaultPartCount:r=R,timeout:o=3e4,headers:s={}}=t,i=e.chainId,a=V(i);if(!a)throw new Error(`Unsupported network: ${i}`);const u=q.getInstance({baseUrl:n,timeout:o,headers:s});return new de({config:{routerAddress:a.routerAddress,bitzyQueryAddress:a.bitzyQueryAddress,wrappedAddress:a.wrappedAddress,nativeAddress:a.nativeAddress},defaultPartCount:r,apiClient:u}).fetchRoute(e)}async function he(e){return(await Promise.allSettled(e.map(async({options:e,config:t})=>{try{return{success:!0,data:await pe(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"})}async function ge(e,t,n,r,o={}){const s=await pe({amountIn:n,srcToken:e,dstToken:t,chainId:r},o);return{amountOut:s.amountOutBN.toFixed(0),routes:s.routes.length}}async function me(e,t={}){const{types:n,enabledSources:r}=M(e.chainId);return pe({...e,types:n,enabledSources:r},{...t,forcePartCount:t.forcePartCount})}const Ee=(t,n,r,u,c={})=>{const l=o(()=>({}),[]),f=o(()=>({routerAddress:e,bitzyQueryAddress:e,wrappedAddress:e,nativeAddress:e}),[]),{apiBaseUrl:d,addressConfig:p,defaultPartCount:h,timeout:g,headers:m,refreshInterval:E,publicClient:A,configTypes:w,configEnabledSources:y,forcePartCount:b,useOnlinePartCount:C}=o(()=>{const{apiBaseUrl:e=_,config:t=f,defaultPartCount:n=5,timeout:r=3e4,headers:o=l,refreshInterval:s=1e4,publicClient:i,types:a,enabledSources:u,forcePartCount:d,useOnlinePartCount:p=!1}=c;return{apiBaseUrl:e,addressConfig:t,defaultPartCount:n,timeout:r,headers:o,refreshInterval:s,publicClient:i,configTypes:a,configEnabledSources:u,forcePartCount:d,useOnlinePartCount:p}},[c,l,f]),O=o(()=>M(u),[u]),I=o(()=>w??O.types,[w,O.types]),v=o(()=>y??O.enabledSources,[y,O.enabledSources]);s(()=>{console.log("config",c)},[c]),s(()=>{console.log("srcToken",t)},[t]),s(()=>{console.log("dstToken",n)},[n]),s(()=>{console.log("amountIn",r)},[r]),s(()=>{console.log("chainId",u)},[u]),s(()=>{console.log("apiBaseUrl",d)},[d]),s(()=>{console.log("addressConfig",p)},[p]),s(()=>{console.log("defaultPartCount",h)},[h]),s(()=>{console.log("timeout",g)},[g]),s(()=>{console.log("headers",m)},[m]),s(()=>{console.log("types",I)},[I]),s(()=>{console.log("enabledSources",v)},[v]);const[D,T]=i(new N(0)),[B,x]=i([]),[P,S]=i([]),[R,F]=i([]),[U,k]=i([]),[L,Q]=i(!1),[z,G]=i(!1),[$,j]=i(),[K,Y]=i(!1),[W,H]=i(null),[X,ee]=i(null),te=o(()=>(console.log("partCount",0,C),C?null!==X?X:Z(t,n,u,h):(console.log("partCount",1,b),void 0!==b?b:(console.log("partCount",2,h),Z(t,n,u,h)))),[h,b,C,X,t,n,u]);s(()=>{if(!(C&&t&&n&&r))return void ee(null);(async()=>{try{const e=await J(t,n,r,u,d,h);ee(e)}catch(e){console.warn("Failed to fetch online partCount:",e),ee(null)}})()},[C,t,n,r,u,d,h]);const ne=o(()=>{const e=V(u),t=p&&Object.keys(p).length>0?p:{routerAddress:e?.routerAddress||"0x0000000000000000000000000000000000000000",bitzyQueryAddress:e?.bitzyQueryAddress||"0x0000000000000000000000000000000000000000",wrappedAddress:e?.wrappedAddress||"0x0000000000000000000000000000000000000000",nativeAddress:e?.nativeAddress||"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"},n=q.getInstance({baseUrl:d,timeout:g,headers:m});return new de({config:t,defaultPartCount:h,apiClient:n,publicClient:A})},[p,h,d,g,m,A,u]),re=a(()=>{H(null)},[]),oe=a(async()=>{if(!t||!n||!r||"0"===r)return T(new N(0)),x([]),S([]),F([]),k([]),G(!1),Y(!1),void H(null);Q(!0),H(null);try{const e={amountIn:r,srcToken:t,dstToken:n,chainId:u,partCount:te,types:I,enabledSources:v},o=await ne.fetchRoute(e);T(o.amountOutBN),x(o.routes),S(o.distributions),F(o.amountOutRoutes),k(o.amountInParts),G(o.isAmountOutError),j(o.isWrap),Y(!0)}catch(e){const t=e instanceof Error?e.message:"Unknown error occurred";H(t),console.error("Error fetching route:",e),T(new N(0)),x([]),S([]),F([]),k([]),G(!0),Y(!1)}finally{Q(!1)}},[ne,t,n,r,u,te,I,v]),se=o(()=>le(oe,300),[oe]);return s(()=>{if(!r||"0"===r)return T(new N(0)),x([]),S([]),F([]),k([]),G(!1),Y(!1),void H(null);se();const e=setInterval(()=>{se()},E);return()=>{clearInterval(e),"function"==typeof se.cancel&&se.cancel()}},[r,t?.address,n?.address,se,E]),s(()=>{K&&oe()},[oe,K,ne]),{routes:B,distributions:P,amountOutRoutes:R,amountOutBN:D,amountInParts:U,fetchRoute:oe,isLoading:L,isAmountOutError:z,isFirstFetch:K,isWrap:$,error:W,clearError:re}};export{q as APIClient,$ as API_ENDPOINTS,fe as BITZY_QUERY_ABI,k as CONTRACT_ADDRESSES,z as DEFAULT_NETWORKS,R as DEFAULT_PART_COUNT,F as DEFAULT_TIMEOUT,x as DEX_INTERFACE,G as DEX_ROUTER,U as DEX_ROUTERS,j as ERROR_CODES,W as HIGH_VALUE_TOKENS,L as LIQUIDITY_SOURCES,S as ROUTER_TARGET,de as SwapV3Service,P as USER_TARGET,ue as calculatePartCount,ee as calculatePriceImpact,Y as clearMinimumAmountsCache,le as debounce,D as ensureBigNumber,he as fetchBatchSwapRoutes,pe as fetchSwapRoute,me as fetchSwapRouteSimple,ce as formatError,ne as fromTokenAmount,V as getContractAddresses,Q as getDexRouters,M as getLiquiditySources,te as getOptimalPartCount,Z as getPartCountOffline,X as getPartCountOnline,J as getPartCountWithFallback,ge as getSwapQuote,pe as getSwapRoute,T as isBigNumber,H as isHighValueToken,oe as isNativeToken,se as isWrappedToken,re as toTokenAmount,Ee as useSwapRoutes,Ee as useSwapV3Routes,ae as validateAmount,ie as validateTokens};
|
|
1
|
+
import{useMemo as e,useEffect as t,useState as n,useCallback as r}from"react";var s=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,i=Math.ceil,o=Math.floor,a="[BigNumber Error] ",c=a+"Number primitive has more than 15 significant digits: ",u=1e14,l=14,f=9007199254740991,d=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],h=1e7,p=1e9;function g(e){var t=0|e;return e>0||e===t?t:t-1}function m(e){for(var t,n,r=1,s=e.length,i=e[0]+"";r<s;){for(t=e[r++]+"",n=l-t.length;n--;t="0"+t);i+=t}for(s=i.length;48===i.charCodeAt(--s););return i.slice(0,s+1||1)}function y(e,t){var n,r,s=e.c,i=t.c,o=e.s,a=t.s,c=e.e,u=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=c==u,!s||!i)return r?0:!s^n?1:-1;if(!r)return c>u^n?1:-1;for(a=(c=s.length)<(u=i.length)?c:u,o=0;o<a;o++)if(s[o]!=i[o])return s[o]>i[o]^n?1:-1;return c==u?0:c>u^n?1:-1}function b(e,t,n,r){if(e<t||e>n||e!==o(e))throw Error(a+(r||"Argument")+("number"==typeof e?e<t||e>n?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function w(e){var t=e.c.length-1;return g(e.e/l)==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 E(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 v=function e(t){var n,r,v,I,x,C,P,O,B,N,$=W.prototype={constructor:W,toString:null,valueOf:null},z=new W(1),D=20,S=4,T=-7,U=21,R=-1e7,F=1e7,L=!1,_=1,k=0,M={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},V="0123456789abcdefghijklmnopqrstuvwxyz",j=!0;function W(e,t){var n,i,a,u,d,h,p,g,m=this;if(!(m instanceof W))return new W(e,t);if(null==t){if(e&&!0===e._isBigNumber)return m.s=e.s,void(!e.c||e.e>F?m.c=m.e=null:e.e<R?m.c=[m.e=0]:(m.e=e.e,m.c=e.c.slice()));if((h="number"==typeof e)&&0*e==0){if(m.s=1/e<0?(e=-e,-1):1,e===~~e){for(u=0,d=e;d>=10;d/=10,u++);return void(u>F?m.c=m.e=null:(m.e=u,m.c=[e]))}g=String(e)}else{if(!s.test(g=String(e)))return v(m,g,h);m.s=45==g.charCodeAt(0)?(g=g.slice(1),-1):1}(u=g.indexOf("."))>-1&&(g=g.replace(".","")),(d=g.search(/e/i))>0?(u<0&&(u=d),u+=+g.slice(d+1),g=g.substring(0,d)):u<0&&(u=g.length)}else{if(b(t,2,V.length,"Base"),10==t&&j)return q(m=new W(e),D+m.e+1,S);if(g=String(e),h="number"==typeof e){if(0*e!=0)return v(m,g,h,t);if(m.s=1/e<0?(g=g.slice(1),-1):1,W.DEBUG&&g.replace(/^0\.0*|\./,"").length>15)throw Error(c+e)}else m.s=45===g.charCodeAt(0)?(g=g.slice(1),-1):1;for(n=V.slice(0,t),u=d=0,p=g.length;d<p;d++)if(n.indexOf(i=g.charAt(d))<0){if("."==i){if(d>u){u=p;continue}}else if(!a&&(g==g.toUpperCase()&&(g=g.toLowerCase())||g==g.toLowerCase()&&(g=g.toUpperCase()))){a=!0,d=-1,u=0;continue}return v(m,String(e),h,t)}h=!1,(u=(g=r(g,t,10,m.s)).indexOf("."))>-1?g=g.replace(".",""):u=g.length}for(d=0;48===g.charCodeAt(d);d++);for(p=g.length;48===g.charCodeAt(--p););if(g=g.slice(d,++p)){if(p-=d,h&&W.DEBUG&&p>15&&(e>f||e!==o(e)))throw Error(c+m.s*e);if((u=u-d-1)>F)m.c=m.e=null;else if(u<R)m.c=[m.e=0];else{if(m.e=u,m.c=[],d=(u+1)%l,u<0&&(d+=l),d<p){for(d&&m.c.push(+g.slice(0,d)),p-=l;d<p;)m.c.push(+g.slice(d,d+=l));d=l-(g=g.slice(d)).length}else d-=p;for(;d--;g+="0");m.c.push(+g)}}else m.c=[m.e=0]}function G(e,t,n,r){var s,i,o,a,c;if(null==n?n=S:b(n,0,8),!e.c)return e.toString();if(s=e.c[0],o=e.e,null==t)c=m(e.c),c=1==r||2==r&&(o<=T||o>=U)?A(c,o):E(c,o,"0");else if(i=(e=q(new W(e),t,n)).e,a=(c=m(e.c)).length,1==r||2==r&&(t<=i||i<=T)){for(;a<t;c+="0",a++);c=A(c,i)}else if(t-=o+(2===r&&i>o),c=E(c,i,"0"),i+1>a){if(--t>0)for(c+=".";t--;c+="0");}else if((t+=i-a)>0)for(i+1==a&&(c+=".");t--;c+="0");return e.s<0&&s?"-"+c:c}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=y(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*l-1)>F?e.c=e.e=null:n<R?e.c=[e.e=0]:(e.e=n,e.c=t),e}function q(e,t,n,r){var s,a,c,f,h,p,g,m=e.c,y=d;if(m){e:{for(s=1,f=m[0];f>=10;f/=10,s++);if((a=t-s)<0)a+=l,c=t,h=m[p=0],g=o(h/y[s-c-1]%10);else if((p=i((a+1)/l))>=m.length){if(!r)break e;for(;m.length<=p;m.push(0));h=g=0,s=1,c=(a%=l)-l+1}else{for(h=f=m[p],s=1;f>=10;f/=10,s++);g=(c=(a%=l)-l+s)<0?0:o(h/y[s-c-1]%10)}if(r=r||t<0||null!=m[p+1]||(c<0?h:h%y[s-c-1]),r=n<4?(g||r)&&(0==n||n==(e.s<0?3:2)):g>5||5==g&&(4==n||r||6==n&&(a>0?c>0?h/y[s-c]:0:m[p-1])%10&1||n==(e.s<0?8:7)),t<1||!m[0])return m.length=0,r?(t-=e.e+1,m[0]=y[(l-t%l)%l],e.e=-t||0):m[0]=e.e=0,e;if(0==a?(m.length=p,f=1,p--):(m.length=p+1,f=y[l-a],m[p]=c>0?o(h/y[s-c]%y[c])*f:0),r)for(;;){if(0==p){for(a=1,c=m[0];c>=10;c/=10,a++);for(c=m[0]+=f,f=1;c>=10;c/=10,f++);a!=f&&(e.e++,m[0]==u&&(m[0]=1));break}if(m[p]+=f,m[p]!=u)break;m[p--]=0,f=1}for(a=m.length;0===m[--a];m.pop());}e.e>F?e.c=e.e=null:e.e<R&&(e.c=[e.e=0])}return e}function K(e){var t,n=e.e;return null===n?e.toString():(t=m(e.c),t=n<=T||n>=U?A(t,n):E(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(a+"Object expected: "+e);if(e.hasOwnProperty(t="DECIMAL_PLACES")&&(b(n=e[t],0,p,t),D=n),e.hasOwnProperty(t="ROUNDING_MODE")&&(b(n=e[t],0,8,t),S=n),e.hasOwnProperty(t="EXPONENTIAL_AT")&&((n=e[t])&&n.pop?(b(n[0],-p,0,t),b(n[1],0,p,t),T=n[0],U=n[1]):(b(n,-p,p,t),T=-(U=n<0?-n:n))),e.hasOwnProperty(t="RANGE"))if((n=e[t])&&n.pop)b(n[0],-p,-1,t),b(n[1],1,p,t),R=n[0],F=n[1];else{if(b(n,-p,p,t),!n)throw Error(a+t+" cannot be zero: "+n);R=-(F=n<0?-n:n)}if(e.hasOwnProperty(t="CRYPTO")){if((n=e[t])!==!!n)throw Error(a+t+" not true or false: "+n);if(n){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw L=!n,Error(a+"crypto unavailable");L=n}else L=n}if(e.hasOwnProperty(t="MODULO_MODE")&&(b(n=e[t],0,9,t),_=n),e.hasOwnProperty(t="POW_PRECISION")&&(b(n=e[t],0,p,t),k=n),e.hasOwnProperty(t="FORMAT")){if("object"!=typeof(n=e[t]))throw Error(a+t+" not an object: "+n);M=n}if(e.hasOwnProperty(t="ALPHABET")){if("string"!=typeof(n=e[t])||/^.?$|[+\-.\s]|(.).*\1/.test(n))throw Error(a+t+" invalid: "+n);j="0123456789"==n.slice(0,10),V=n}}return{DECIMAL_PLACES:D,ROUNDING_MODE:S,EXPONENTIAL_AT:[T,U],RANGE:[R,F],CRYPTO:L,MODULO_MODE:_,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,r=e.c,s=e.e,i=e.s;e:if("[object Array]"=={}.toString.call(r)){if((1===i||-1===i)&&s>=-p&&s<=p&&s===o(s)){if(0===r[0]){if(0===s&&1===r.length)return!0;break e}if((t=(s+1)%l)<1&&(t+=l),String(r[0]).length==t){for(t=0;t<r.length;t++)if((n=r[t])<0||n>=u||n!==o(n))break e;if(0!==n)return!0}}}else if(null===r&&null===s&&(null===i||1===i||-1===i))return!0;throw Error(a+"Invalid BigNumber: "+e)},W.maximum=W.max=function(){return Q(arguments,-1)},W.minimum=W.min=function(){return Q(arguments,1)},W.random=(I=9007199254740992,x=Math.random()*I&2097151?function(){return o(Math.random()*I)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(e){var t,n,r,s,c,u=0,f=[],h=new W(z);if(null==e?e=D:b(e,0,p),s=i(e/l),L)if(crypto.getRandomValues){for(t=crypto.getRandomValues(new Uint32Array(s*=2));u<s;)(c=131072*t[u]+(t[u+1]>>>11))>=9e15?(n=crypto.getRandomValues(new Uint32Array(2)),t[u]=n[0],t[u+1]=n[1]):(f.push(c%1e14),u+=2);u=s/2}else{if(!crypto.randomBytes)throw L=!1,Error(a+"crypto unavailable");for(t=crypto.randomBytes(s*=7);u<s;)(c=281474976710656*(31&t[u])+1099511627776*t[u+1]+4294967296*t[u+2]+16777216*t[u+3]+(t[u+4]<<16)+(t[u+5]<<8)+t[u+6])>=9e15?crypto.randomBytes(7).copy(t,u):(f.push(c%1e14),u+=7);u=s/7}if(!L)for(;u<s;)(c=x())<9e15&&(f[u++]=c%1e14);for(s=f[--u],e%=l,s&&e&&(c=d[l-e],f[u]=o(s/c)*c);0===f[u];f.pop(),u--);if(u<0)f=[r=0];else{for(r=-1;0===f[0];f.splice(0,1),r-=l);for(u=1,c=f[0];c>=10;c/=10,u++);u<l&&(r-=l-u)}return h.e=r,h.c=f,h}),W.sum=function(){for(var e=1,t=arguments,n=new W(t[0]);e<t.length;)n=n.plus(t[e++]);return n},r=function(){var e="0123456789";function t(e,t,n,r){for(var s,i,o=[0],a=0,c=e.length;a<c;){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(r,s,i,o,a){var c,u,l,f,d,h,p,g,y=r.indexOf("."),b=D,w=S;for(y>=0&&(f=k,k=0,r=r.replace(".",""),h=(g=new W(s)).pow(r.length-y),k=f,g.c=t(E(m(h.c),h.e,"0"),10,i,e),g.e=g.c.length),l=f=(p=t(r,s,i,a?(c=V,e):(c=e,V))).length;0==p[--f];p.pop());if(!p[0])return c.charAt(0);if(y<0?--l:(h.c=p,h.e=l,h.s=o,p=(h=n(h,g,b,w,i)).c,d=h.r,l=h.e),y=p[u=l+b+1],f=i/2,d=d||u<0||null!=p[u+1],d=w<4?(null!=y||d)&&(0==w||w==(h.s<0?3:2)):y>f||y==f&&(4==w||d||6==w&&1&p[u-1]||w==(h.s<0?8:7)),u<1||!p[0])r=d?E(c.charAt(1),-b,c.charAt(0)):c.charAt(0);else{if(p.length=u,d)for(--i;++p[--u]>i;)p[u]=0,u||(++l,p=[1].concat(p));for(f=p.length;!p[--f];);for(y=0,r="";y<=f;r+=c.charAt(p[y++]));r=E(r,l,c.charAt(0))}return r}}(),n=function(){function e(e,t,n){var r,s,i,o,a=0,c=e.length,u=t%h,l=t/h|0;for(e=e.slice();c--;)a=((s=u*(i=e[c]%h)+(r=l*i+(o=e[c]/h|0)*u)%h*h+a)/n|0)+(r/h|0)+l*o,e[c]=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(r,s,i,a,c){var f,d,h,p,m,y,b,w,A,E,v,I,x,C,P,O,B,N=r.s==s.s?1:-1,$=r.c,z=s.c;if(!($&&$[0]&&z&&z[0]))return new W(r.s&&s.s&&($?!z||$[0]!=z[0]:z)?$&&0==$[0]||!z?0*N:N/0:NaN);for(A=(w=new W(N)).c=[],N=i+(d=r.e-s.e)+1,c||(c=u,d=g(r.e/l)-g(s.e/l),N=N/l|0),h=0;z[h]==($[h]||0);h++);if(z[h]>($[h]||0)&&d--,N<0)A.push(1),p=!0;else{for(C=$.length,O=z.length,h=0,N+=2,(m=o(c/(z[0]+1)))>1&&(z=e(z,m,c),$=e($,m,c),O=z.length,C=$.length),x=O,v=(E=$.slice(0,O)).length;v<O;E[v++]=0);B=z.slice(),B=[0].concat(B),P=z[0],z[1]>=c/2&&P++;do{if(m=0,(f=t(z,E,O,v))<0){if(I=E[0],O!=v&&(I=I*c+(E[1]||0)),(m=o(I/P))>1)for(m>=c&&(m=c-1),b=(y=e(z,m,c)).length,v=E.length;1==t(y,E,b,v);)m--,n(y,O<b?B:z,b,c),b=y.length,f=1;else 0==m&&(f=m=1),b=(y=z.slice()).length;if(b<v&&(y=[0].concat(y)),n(E,y,v,c),v=E.length,-1==f)for(;t(z,E,O,v)<1;)m++,n(E,O<v?B:z,v,c),v=E.length}else 0===f&&(m++,E=[0]);A[h++]=m,E[0]?E[v++]=$[x]||0:(E=[$[x]],v=1)}while((x++<C||null!=E[0])&&N--);p=null!=E[0],A[0]||A.splice(0,1)}if(c==u){for(h=1,N=A[0];N>=10;N/=10,h++);q(w,i+(w.e=h+d*l-1)+1,a,p)}else w.e=d,w.r=+p;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 s,i=n?t:t.replace(N,"");if(B.test(i))e.s=isNaN(i)?null:i<0?-1:1;else{if(!n&&(i=i.replace(C,function(e,t,n){return s="x"==(n=n.toLowerCase())?16:"b"==n?2:8,r&&r!=s?e:t}),r&&(s=r,i=i.replace(P,"$1").replace(O,"0.$1")),t!=i))return new W(i,s);if(W.DEBUG)throw Error(a+"Not a"+(r?" base "+r:"")+" number: "+t);e.s=null}e.c=e.e=null},$.absoluteValue=$.abs=function(){var e=new W(this);return e.s<0&&(e.s=1),e},$.comparedTo=function(e,t){return y(this,new W(e,t))},$.decimalPlaces=$.dp=function(e,t){var n,r,s,i=this;if(null!=e)return b(e,0,p),null==t?t=S:b(t,0,8),q(new W(i),e+i.e+1,t);if(!(n=i.c))return null;if(r=((s=n.length-1)-g(this.e/l))*l,s=n[s])for(;s%10==0;s/=10,r--);return r<0&&(r=0),r},$.dividedBy=$.div=function(e,t){return n(this,new W(e,t),D,S)},$.dividedToIntegerBy=$.idiv=function(e,t){return n(this,new W(e,t),0,1)},$.exponentiatedBy=$.pow=function(e,t){var n,r,s,c,u,f,d,h,p=this;if((e=new W(e)).c&&!e.isInteger())throw Error(a+"Exponent not an integer: "+K(e));if(null!=t&&(t=new W(t)),u=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),u?e.s*(2-w(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);(r=!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||u&&p.c[1]>=24e7:p.c[0]<8e13||u&&p.c[0]<=9999975e7)))return c=p.s<0&&w(e)?-0:0,p.e>-1&&(c=1/c),new W(f?1/c:c);k&&(c=i(k/l+2))}for(u?(n=new W(.5),f&&(e.s=1),d=w(e)):d=(s=Math.abs(+K(e)))%2,h=new W(z);;){if(d){if(!(h=h.times(p)).c)break;c?h.c.length>c&&(h.c.length=c):r&&(h=h.mod(t))}if(s){if(0===(s=o(s/2)))break;d=s%2}else if(q(e=e.times(n),e.e+1,1),e.e>14)d=w(e);else{if(0===(s=+K(e)))break;d=s%2}p=p.times(p),c?p.c&&p.c.length>c&&(p.c.length=c):r&&(p=p.mod(t))}return r?h:(f&&(h=z.div(h)),t?h.mod(t):c?q(h,k,S,undefined):h)},$.integerValue=function(e){var t=new W(this);return null==e?e=S:b(e,0,8),q(t,t.e+1,e)},$.isEqualTo=$.eq=function(e,t){return 0===y(this,new W(e,t))},$.isFinite=function(){return!!this.c},$.isGreaterThan=$.gt=function(e,t){return y(this,new W(e,t))>0},$.isGreaterThanOrEqualTo=$.gte=function(e,t){return 1===(t=y(this,new W(e,t)))||0===t},$.isInteger=function(){return!!this.c&&g(this.e/l)>this.c.length-2},$.isLessThan=$.lt=function(e,t){return y(this,new W(e,t))<0},$.isLessThanOrEqualTo=$.lte=function(e,t){return-1===(t=y(this,new W(e,t)))||0===t},$.isNaN=function(){return!this.s},$.isNegative=function(){return this.s<0},$.isPositive=function(){return this.s>0},$.isZero=function(){return!!this.c&&0==this.c[0]},$.minus=function(e,t){var n,r,s,i,o=this,a=o.s;if(t=(e=new W(e,t)).s,!a||!t)return new W(NaN);if(a!=t)return e.s=-t,o.plus(e);var c=o.e/l,f=e.e/l,d=o.c,h=e.c;if(!c||!f){if(!d||!h)return d?(e.s=-t,e):new W(h?o:NaN);if(!d[0]||!h[0])return h[0]?(e.s=-t,e):new W(d[0]?o:3==S?-0:0)}if(c=g(c),f=g(f),d=d.slice(),a=c-f){for((i=a<0)?(a=-a,s=d):(f=c,s=h),s.reverse(),t=a;t--;s.push(0));s.reverse()}else for(r=(i=(a=d.length)<(t=h.length))?a:t,a=t=0;t<r;t++)if(d[t]!=h[t]){i=d[t]<h[t];break}if(i&&(s=d,d=h,h=s,e.s=-e.s),(t=(r=h.length)-(n=d.length))>0)for(;t--;d[n++]=0);for(t=u-1;r>a;){if(d[--r]<h[r]){for(n=r;n&&!d[--n];d[n]=t);--d[n],d[r]+=u}d[r]-=h[r]}for(;0==d[0];d.splice(0,1),--f);return d[0]?Y(e,d,f):(e.s=3==S?-1:1,e.c=[e.e=0],e)},$.modulo=$.mod=function(e,t){var r,s,i=this;return e=new W(e,t),!i.c||!e.s||e.c&&!e.c[0]?new W(NaN):!e.c||i.c&&!i.c[0]?new W(i):(9==_?(s=e.s,e.s=1,r=n(i,e,0,3),e.s=s,r.s*=s):r=n(i,e,0,_),(e=i.minus(r.times(e))).c[0]||1!=_||(e.s=i.s),e)},$.multipliedBy=$.times=function(e,t){var n,r,s,i,o,a,c,f,d,p,m,y,b,w,A,E=this,v=E.c,I=(e=new W(e,t)).c;if(!(v&&I&&v[0]&&I[0]))return!E.s||!e.s||v&&!v[0]&&!I||I&&!I[0]&&!v?e.c=e.e=e.s=null:(e.s*=E.s,v&&I?(e.c=[0],e.e=0):e.c=e.e=null),e;for(r=g(E.e/l)+g(e.e/l),e.s*=E.s,(c=v.length)<(p=I.length)&&(b=v,v=I,I=b,s=c,c=p,p=s),s=c+p,b=[];s--;b.push(0));for(w=u,A=h,s=p;--s>=0;){for(n=0,m=I[s]%A,y=I[s]/A|0,i=s+(o=c);i>s;)n=((f=m*(f=v[--o]%A)+(a=y*f+(d=v[o]/A|0)*m)%A*A+b[i]+n)/w|0)+(a/A|0)+y*d,b[i--]=f%w;b[i]=n}return n?++r:b.splice(0,1),Y(e,b,r)},$.negated=function(){var e=new W(this);return e.s=-e.s||null,e},$.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/l,o=e.e/l,a=r.c,c=e.c;if(!i||!o){if(!a||!c)return new W(s/0);if(!a[0]||!c[0])return c[0]?e:new W(a[0]?r:0*s)}if(i=g(i),o=g(o),a=a.slice(),s=i-o){for(s>0?(o=i,n=c):(s=-s,n=a),n.reverse();s--;n.push(0));n.reverse()}for((s=a.length)-(t=c.length)<0&&(n=c,c=a,a=n,t=s),s=0;t;)s=(a[--t]=a[t]+c[t]+s)/u|0,a[t]=u===a[t]?0:a[t]%u;return s&&(a=[s].concat(a),++o),Y(e,a,o)},$.precision=$.sd=function(e,t){var n,r,s,i=this;if(null!=e&&e!==!!e)return b(e,1,p),null==t?t=S:b(t,0,8),q(new W(i),e,t);if(!(n=i.c))return null;if(r=(s=n.length-1)*l+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},$.shiftedBy=function(e){return b(e,-9007199254740991,f),this.times("1e"+e)},$.squareRoot=$.sqrt=function(){var e,t,r,s,i,o=this,a=o.c,c=o.s,u=o.e,l=D+4,f=new W("0.5");if(1!==c||!a||!a[0])return new W(!c||c<0&&(!a||a[0])?NaN:a?o:1/0);if(0==(c=Math.sqrt(+K(o)))||c==1/0?(((t=m(a)).length+u)%2==0&&(t+="0"),c=Math.sqrt(+t),u=g((u+1)/2)-(u<0||u%2),r=new W(t=c==1/0?"5e"+u:(t=c.toExponential()).slice(0,t.indexOf("e")+1)+u)):r=new W(c+""),r.c[0])for((c=(u=r.e)+l)<3&&(c=0);;)if(i=r,r=f.times(i.plus(n(o,i,l,1))),m(i.c).slice(0,c)===(t=m(r.c)).slice(0,c)){if(r.e<u&&--c,"9999"!=(t=t.slice(c-3,c+1))&&(s||"4999"!=t)){+t&&(+t.slice(1)||"5"!=t.charAt(0))||(q(r,r.e+D+2,1),e=!r.times(r).eq(o));break}if(!s&&(q(i,i.e+D+2,0),i.times(i).eq(o))){r=i;break}l+=4,c+=4,s=1}return q(r,r.e+D+1,S,e)},$.toExponential=function(e,t){return null!=e&&(b(e,0,p),e++),G(this,e,t,1)},$.toFixed=function(e,t){return null!=e&&(b(e,0,p),e=e+this.e+1),G(this,e,t)},$.toFormat=function(e,t,n){var r,s=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(a+"Argument not an object: "+n);if(r=s.toFixed(e,t),s.c){var i,o=r.split("."),c=+n.groupSize,u=+n.secondaryGroupSize,l=n.groupSeparator||"",f=o[0],d=o[1],h=s.s<0,p=h?f.slice(1):f,g=p.length;if(u&&(i=c,c=u,u=i,g-=i),c>0&&g>0){for(i=g%c||c,f=p.substr(0,i);i<g;i+=c)f+=l+p.substr(i,c);u>0&&(f+=l+p.slice(i)),h&&(f="-"+f)}r=d?f+(n.decimalSeparator||"")+((u=+n.fractionGroupSize)?d.replace(new RegExp("\\d{"+u+"}\\B","g"),"$&"+(n.fractionGroupSeparator||"")):d):f}return(n.prefix||"")+r+(n.suffix||"")},$.toFraction=function(e){var t,r,s,i,o,c,u,f,h,p,g,y,b=this,w=b.c;if(null!=e&&(!(u=new W(e)).isInteger()&&(u.c||1!==u.s)||u.lt(z)))throw Error(a+"Argument "+(u.isInteger()?"out of range: ":"not an integer: ")+K(u));if(!w)return new W(b);for(t=new W(z),h=r=new W(z),s=f=new W(z),y=m(w),o=t.e=y.length-b.e-1,t.c[0]=d[(c=o%l)<0?l+c:c],e=!e||u.comparedTo(t)>0?o>0?t:h:u,c=F,F=1/0,u=new W(y),f.c[0]=0;p=n(u,t,0,1),1!=(i=r.plus(p.times(s))).comparedTo(e);)r=s,s=i,h=f.plus(p.times(i=h)),f=i,t=u.minus(p.times(i=t)),u=i;return i=n(e.minus(r),s,0,1),f=f.plus(i.times(h)),r=r.plus(i.times(s)),f.s=h.s=b.s,g=n(h,s,o*=2,S).minus(b).abs().comparedTo(n(f,r,o,S).minus(b).abs())<1?[h,s]:[f,r],F=c,g},$.toNumber=function(){return+K(this)},$.toPrecision=function(e,t){return null!=e&&b(e,1,p),G(this,e,t,2)},$.toString=function(e){var t,n=this,s=n.s,i=n.e;return null===i?s?(t="Infinity",s<0&&(t="-"+t)):t="NaN":(null==e?t=i<=T||i>=U?A(m(n.c),i):E(m(n.c),i,"0"):10===e&&j?t=E(m((n=q(new W(n),D+i+1,S)).c),n.e,"0"):(b(e,2,V.length,"Base"),t=r(E(m(n.c),i,"0"),10,e,s,!0)),s<0&&n.c[0]&&(t="-"+t)),t},$.valueOf=$.toJSON=function(){return K(this)},$._isBigNumber=!0,$[Symbol.toStringTag]="BigNumber",$[Symbol.for("nodejs.util.inspect.custom")]=$.valueOf,null!=t&&W.set(t),W}();const I=/^tuple(?<array>(\[(\d*)\])*)$/;function x(e){let t=e.type;if(I.test(e.type)&&"components"in e){t="(";const n=e.components.length;for(let r=0;r<n;r++){t+=x(e.components[r]),r<n-1&&(t+=", ")}const r=function(e,t){const n=e.exec(t);return n?.groups}(I,e.type);return t+=`)${r?.array??""}`,x({...e,type:t})}return"indexed"in e&&e.indexed&&(t=`${t} indexed`),e.name?`${t} ${e.name}`:t}function C(e){let t="";const n=e.length;for(let r=0;r<n;r++){t+=x(e[r]),r!==n-1&&(t+=", ")}return t}function P(e,{includeName:t=!1}={}){if("function"!==e.type&&"event"!==e.type&&"error"!==e.type)throw new Q(e.type);return`${e.name}(${O(e.inputs,{includeName:t})})`}function O(e,{includeName:t=!1}={}){return e?e.map(e=>function(e,{includeName:t}){if(e.type.startsWith("tuple"))return`(${O(e.components,{includeName:t})})${e.type.slice(5)}`;return e.type+(t&&e.name?` ${e.name}`:"")}(e,{includeName:t})).join(t?", ":","):""}function B(e,{strict:t=!0}={}){return!!e&&("string"==typeof e&&(t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")))}function N(e){return B(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}const $="2.36.0";let z=({docsBaseUrl:e,docsPath:t="",docsSlug:n})=>t?`${e??"https://viem.sh"}${t}${n?`#${n}`:""}`:void 0,D=`viem@${$}`;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=z?.({...t,docsPath:r});super([e||"An error occurred.","",...t.metaMessages?[...t.metaMessages,""]:[],...s?[`Docs: ${s}`]:[],...n?[`Details: ${n}`]:[],...D?[`Version: ${D}`]:[]].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=$}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 U 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: (${O(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 F 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 L extends S{constructor({expectedSize:e,value:t}){super(`Size of bytes "${t}" (bytes${N(t)}) does not match expected size (bytes${e}).`,{name:"AbiEncodingBytesSizeMismatchError"})}}class _ 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 k 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 M 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 V extends S{constructor(e,t){super("Found ambiguous types in overloaded ABI items.",{metaMessages:[`\`${e.type}\` in \`${P(e.abiItem)}\`, and`,`\`${t.type}\` in \`${P(t.abiItem)}\``,"","These types encode differently and cannot be distinguished at runtime.","Remove one of the ambiguous items in the ABI."],name:"AbiItemAmbiguityError"})}}class j 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 W 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 G extends S{constructor(e){super([`Value "${e}" is not a valid array.`].join("\n"),{name:"InvalidArrayError"})}}class Q extends S{constructor(e){super([`"${e}" is not a valid definition type.`,'Valid types: "function", "event", "error"'].join("\n"),{name:"InvalidDefinitionTypeError"})}}class Y 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 q 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 K(e,{dir:t,size:n=32}={}){return"string"==typeof e?H(e,{dir:t,size:n}):function(e,{dir:t,size:n=32}={}){if(null===n)return e;if(e.length>n)throw new q({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 H(e,{dir:t,size:n=32}={}){if(null===n)return e;const r=e.replace("0x","");if(r.length>2*n)throw new q({size:Math.ceil(r.length/2),targetSize:n,type:"hex"});return`0x${r["right"===t?"padEnd":"padStart"](2*n,"0")}`}class X 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 Z 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 J extends S{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:"SizeOverflowError"})}}function ee(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 te(e,{size:t}){if(N(e)>t)throw new J({givenSize:N(e),maxSize:t})}function ne(e,t={}){const{signed:n}=t;t.size&&te(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 re=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function se(e,t={}){const n=`0x${Number(e)}`;return"number"==typeof t.size?(te(n,{size:t.size}),K(n,{size:t.size})):n}function ie(e,t={}){let n="";for(let t=0;t<e.length;t++)n+=re[e[t]];const r=`0x${n}`;return"number"==typeof t.size?(te(r,{size:t.size}),K(r,{dir:"right",size:t.size})):r}function oe(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 X({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?K(a,{size:r}):a}const ae=new TextEncoder;function ce(e,t={}){return ie(ae.encode(e),t)}const ue=new TextEncoder;function le(e,t={}){return"number"==typeof e||"bigint"==typeof e?function(e,t){const n=oe(e,t);return he(n)}(e,t):"boolean"==typeof e?function(e,t={}){const n=new Uint8Array(1);if(n[0]=Number(e),"number"==typeof t.size)return te(n,{size:t.size}),K(n,{size:t.size});return n}(e,t):B(e)?he(e,t):pe(e,t)}const fe={zero:48,nine:57,A:65,F:70,a:97,f:102};function de(e){return e>=fe.zero&&e<=fe.nine?e-fe.zero:e>=fe.A&&e<=fe.F?e-(fe.A-10):e>=fe.a&&e<=fe.f?e-(fe.a-10):void 0}function he(e,t={}){let n=e;t.size&&(te(n,{size:t.size}),n=K(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=de(r.charCodeAt(t++)),s=de(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 pe(e,t={}){const n=ue.encode(e);return"number"==typeof t.size?(te(n,{size:t.size}),K(n,{dir:"right",size:t.size})):n}const ge=BigInt(2**32-1),me=BigInt(32);function ye(e,t=!1){return t?{h:Number(e&ge),l:Number(e>>me&ge)}:{h:0|Number(e>>me&ge),l:0|Number(e&ge)}}function be(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function we(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 Ae(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 Ee(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function ve(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const Ie=(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])()?e=>e:function(e){for(let t=0;t<e.length;t++)e[t]=ve(e[t]);return e};function xe(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)),we(e),e}class Ce{}const Pe=BigInt(0),Oe=BigInt(1),Be=BigInt(2),Ne=BigInt(7),$e=BigInt(256),ze=BigInt(113),De=[],Se=[],Te=[];for(let e=0,t=Oe,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],De.push(2*(5*r+n)),Se.push((e+1)*(e+2)/2%64);let s=Pe;for(let e=0;e<7;e++)t=(t<<Oe^(t>>Ne)*ze)%$e,t&Be&&(s^=Oe<<(Oe<<BigInt(e))-Oe);Te.push(s)}const Ue=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}=ye(e[i],t);[r[i],s[i]]=[n,o]}return[r,s]}(Te,!0),Re=Ue[0],Fe=Ue[1],Le=(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),_e=(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 ke extends Ce{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,be(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(){Ie(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=Le(i,o,1)^n[r],c=_e(i,o,1)^n[r+1];for(let n=0;n<50;n+=10)e[t+n]^=a,e[t+n+1]^=c}let t=e[2],s=e[3];for(let n=0;n<24;n++){const r=Se[n],i=Le(t,s,r),o=_e(t,s,r),a=De[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]^=Fe[r]}Ee(n)}(this.state32,this.rounds),Ie(this.state32),this.posOut=0,this.pos=0}update(e){Ae(this),we(e=xe(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){Ae(this,!1),we(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 be(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(function(e,t){we(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,Ee(this.state)}_cloneInto(e){const{blockLen:t,suffix:n,outputLen:r,rounds:s,enableXOF:i}=this;return e||(e=new ke(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 Me=(e,t,n)=>function(e){const t=t=>e().update(xe(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}(()=>new ke(t,e,n)),Ve=(()=>Me(1,136,32))();function je(e,t){const n=t||"hex",r=Ve(B(e,{strict:!1})?le(e):e);return"bytes"===n?r:function(e,t={}){return"number"==typeof e||"bigint"==typeof e?oe(e,t):"string"==typeof e?ce(e,t):"boolean"==typeof e?se(e,t):ie(e,t)}(r)}function We(e){return je(le(e))}const Ge=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}(${C(t.inputs)})${t.stateMutability&&"nonpayable"!==t.stateMutability?` ${t.stateMutability}`:""}${t.outputs?.length?` returns (${C(t.outputs)})`:""}`:"event"===t.type?`event ${t.name}(${C(t.inputs)})`:"error"===t.type?`error ${t.name}(${C(t.inputs)})`:"constructor"===t.type?`constructor(${C(t.inputs)})${"payable"===t.stateMutability?" payable":""}`:"fallback"===t.type?"fallback() external"+("payable"===t.stateMutability?" payable":""):"receive() external payable")};function Qe(e){return We(Ge(e))}const Ye=Qe;class qe 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 Ke 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 He=new Ke(8192);function Xe(e,t){if(He.has(`${e}.${t}`))return He.get(`${e}.${t}`);const n=e.substring(2).toLowerCase(),r=je(pe(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 He.set(`${e}.${t}`,i),i}const Ze=/^0x[a-fA-F0-9]{40}$/,Je=new Ke(8192);function et(e,t){const{strict:n=!0}=t??{},r=`${e}.${n}`;if(Je.has(r))return Je.get(r);const s=!(!Ze.test(e)||e.toLowerCase()!==e&&n&&Xe(e)!==e);return Je.set(r,s),s}function tt(e){return"string"==typeof e[0]?nt(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 nt(e){return`0x${e.reduce((e,t)=>e+t.replace("0x",""),"")}`}function rt(e,t,n,{strict:r}={}){return B(e,{strict:!1})?function(e,t,n,{strict:r}={}){st(e,t);const s=`0x${e.replace("0x","").slice(2*(t??0),2*(n??e.length))}`;r&&it(s,t,n);return s}(e,t,n,{strict:r}):ot(e,t,n,{strict:r})}function st(e,t){if("number"==typeof t&&t>0&&t>N(e)-1)throw new Y({offset:t,position:"start",size:N(e)})}function it(e,t,n){if("number"==typeof t&&"number"==typeof n&&N(e)!==n-t)throw new Y({offset:n,position:"end",size:N(e)})}function ot(e,t,n,{strict:r}={}){st(e,t);const s=e.slice(t,n);return r&&it(s,t,n),s}const at=/^(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 ct(e,t){if(e.length!==t.length)throw new _({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(ut({param:e[r],value:t[r]}));return n}({params:e,values:t}),r=lt(n);return 0===r.length?"0x":r}function ut({param:e,value:t}){const n=ft(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 G(e);if(!r&&e.length!==t)throw new F({expectedLength:t,givenLength:e.length,type:`${n.type}[${t}]`});let s=!1;const i=[];for(let t=0;t<e.length;t++){const r=ut({param:n,value:e[t]});r.dynamic&&(s=!0),i.push(r)}if(r||s){const e=lt(i);if(r){const t=oe(i.length,{size:32});return{dynamic:!0,encoded:i.length>0?tt([t,e]):t}}if(s)return{dynamic:!0,encoded:e}}return{dynamic:!1,encoded:tt(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=ut({param:i,value:e[Array.isArray(e)?s:i.name]});r.push(o),o.dynamic&&(n=!0)}return{dynamic:n,encoded:n?lt(r):tt(r.map(({encoded:e})=>e))}}(t,{param:e});if("address"===e.type)return function(e){if(!et(e))throw new qe({address:e});return{dynamic:!1,encoded:H(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:H(se(e))}}(t);if(e.type.startsWith("uint")||e.type.startsWith("int")){const n=e.type.startsWith("int"),[,,r="256"]=at.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 X({max:r.toString(),min:s.toString(),signed:t,size:n/8,value:e.toString()})}return{dynamic:!1,encoded:oe(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=N(e);if(!n){let t=e;return r%32!=0&&(t=H(t,{dir:"right",size:32*Math.ceil((e.length-2)/2/32)})),{dynamic:!0,encoded:tt([H(oe(r,{size:32})),t])}}if(r!==Number.parseInt(n,10))throw new L({expectedSize:Number.parseInt(n,10),value:e});return{dynamic:!1,encoded:H(e,{dir:"right"})}}(t,{param:e});if("string"===e.type)return function(e){const t=ce(e),n=Math.ceil(N(t)/32),r=[];for(let e=0;e<n;e++)r.push(H(rt(t,32*e,32*(e+1)),{dir:"right"}));return{dynamic:!0,encoded:tt([H(oe(N(t),{size:32})),...r])}}(t);throw new j(e.type,{docsPath:"/docs/contract/encodeAbiParameters"})}function lt(e){let t=0;for(let n=0;n<e.length;n++){const{dynamic:r,encoded:s}=e[n];t+=r?32:N(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(oe(t+s,{size:32})),r.push(a),s+=N(a)):n.push(a)}return tt([...n,...r])}function ft(e){const t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}const dt=e=>rt(Qe(e),0,4);function ht(e){const{abi:t,args:n=[],name:r}=e,s=B(r,{strict:!1}),i=t.filter(e=>s?"function"===e.type?dt(e)===r:"event"===e.type&&Ye(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&&pt(t,r)})){if(o&&"inputs"in o&&o.inputs){const t=gt(e.inputs,o.inputs,n);if(t)throw new V({abiItem:e,type:t[0]},{abiItem:o,type:t[1]})}o=e}}return o||i[0]}function pt(e,t){const n=typeof e,r=t.type;switch(r){case"address":return et(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)=>pt(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=>pt(e,{...t,type:r.replace(/(\[[0-9]{0,}\])$/,"")})))}}function gt(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 gt(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")))&&et(n[r],{strict:!1}))())return o}}const mt="/docs/contract/encodeFunctionData";function yt(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=ht({abi:t,args:n,name:r});if(!e)throw new k(r,{docsPath:mt});s=e}if("function"!==s.type)throw new k(void 0,{docsPath:mt});return{abi:[s],functionName:dt(P(s))}}(e),s=n[0];return nt([r,("inputs"in s&&s.inputs?ct(s.inputs,t??[]):void 0)??"0x"])}class bt extends S{constructor({offset:e}){super(`Offset \`${e}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class wt extends S{constructor({length:e,position:t}){super(`Position \`${t}\` is out of bounds (\`0 < position < ${e}\`).`,{name:"PositionOutOfBoundsError"})}}class At extends S{constructor({count:e,limit:t}){super(`Recursive read limit of \`${t}\` exceeded (recursive read count: \`${e}\`).`,{name:"RecursiveReadLimitExceededError"})}}const Et={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 At({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new wt({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new bt({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 bt({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 vt(e,t={}){void 0!==t.size&&te(e,{size:t.size});return ne(ie(e,t),t)}function It(e,t={}){let n=e;if(void 0!==t.size&&(te(n,{size:t.size}),n=ee(n)),n.length>1||n[0]>1)throw new Z(n);return Boolean(n[0])}function xt(e,t={}){void 0!==t.size&&te(e,{size:t.size});return function(e,t={}){return Number(ne(e,t))}(ie(e,t),t)}function Ct(e,t){const n="string"==typeof t?he(t):t,r=function(e,{recursiveReadLimit:t=8192}={}){const n=Object.create(Et);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===N(n)&&e.length>0)throw new R;if(N(t)&&N(t)<32)throw new U({data:"string"==typeof t?t:ie(t),params:e,size:N(t)});let s=0;const i=[];for(let t=0;t<e.length;++t){const n=e[t];r.setPosition(s);const[o,a]=Pt(r,n,{staticPosition:0});s+=a,i.push(o)}return i}function Pt(e,t,{staticPosition:n}){const r=ft(t.type);if(r){const[s,i]=r;return function(e,t,{length:n,staticPosition:r}){if(!n){const n=r+xt(e.readBytes(Bt)),s=n+Ot;e.setPosition(n);const i=xt(e.readBytes(Ot)),o=Nt(t);let a=0;const c=[];for(let n=0;n<i;++n){e.setPosition(s+(o?32*n:a));const[r,i]=Pt(e,t,{staticPosition:s});a+=i,c.push(r)}return e.setPosition(r+32),[c,32]}if(Nt(t)){const s=r+xt(e.readBytes(Bt)),i=[];for(let r=0;r<n;++r){e.setPosition(s+32*r);const[n]=Pt(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]=Pt(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(Nt(t)){const o=n+xt(e.readBytes(Bt));for(let n=0;n<t.components.length;++n){const a=t.components[n];e.setPosition(o+i);const[c,u]=Pt(e,a,{staticPosition:o});i+=u,s[r?n:a?.name]=c}return e.setPosition(n+32),[s,32]}for(let o=0;o<t.components.length;++o){const a=t.components[o],[c,u]=Pt(e,a,{staticPosition:n});s[r?o:a?.name]=c,i+=u}return[s,i]}(e,t,{staticPosition:n});if("address"===t.type)return function(e){const t=e.readBytes(32);return[Xe(ie(ot(t,-20))),32]}(e);if("bool"===t.type)return function(e){return[It(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=xt(e.readBytes(32));e.setPosition(n+t);const r=xt(e.readBytes(32));if(0===r)return e.setPosition(n+32),["0x",32];const s=e.readBytes(r);return e.setPosition(n+32),[ie(s),32]}const i=ie(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?vt(s,{signed:n}):xt(s,{signed:n}),32]}(e,t);if("string"===t.type)return function(e,{staticPosition:t}){const n=xt(e.readBytes(32)),r=t+n;e.setPosition(r);const s=xt(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&&(te(n,{size:t.size}),n=ee(n,{dir:"right"})),(new TextDecoder).decode(n)}(ee(i));return e.setPosition(t+32),[o,32]}(e,{staticPosition:n});throw new W(t.type,{docsPath:"/docs/contract/decodeAbiParameters"})}const Ot=32,Bt=32;function Nt(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(Nt);const n=ft(e.type);return!(!n||!Nt({...e,type:n[1]}))}const $t="/docs/contract/decodeFunctionResult";const zt="0x0000000000000000000000000000000000000000",Dt=e=>e instanceof v?e:new v(e),St=e=>e instanceof v;class Tt extends Error{constructor(e){super(e.message),this.name="SwapError",this.code=e.code,this.details=e.details,Error.captureStackTrace&&Error.captureStackTrace(this,Tt)}}const Ut={V2:0,V3:1},Rt="0x0000000000000000000000000000000000000001",Ft="0x0000000000000000000000000000000000000000",Lt=5,_t=3e4,kt="https://api-public.bitzy.app",Mt={3637:{BITZY_V3:"0xA5E0AE4e5103dc71cA290AA3654830442357A489",BITZY_V2:"0x07c49Ade88b40f1Ac05707f236d7706f834F6BDB",AVOCADO_V2:"0xA4B4cDeC4fE2839d3D3a49Ad5E20c21c01A31091"},3636:{BITZY_V3:"0xA5E0AE4e5103dc71cA290AA3654830442357A489",BITZY_V2:"0x07c49Ade88b40f1Ac05707f236d7706f834F6BDB",AVOCADO_V2:"0xA4B4cDeC4fE2839d3D3a49Ad5E20c21c01A31091"}},Vt={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)}},jt={3637:{types:[1,2],enabledSources:[1]},3636:{types:[1,2],enabledSources:[1]}},Wt=e=>jt[e]||{types:[1,2],enabledSources:[1]},Gt=e=>Vt[e],Qt=e=>Mt[e]||{},Yt=Vt,qt=Mt[3637]||{},Kt={PATH_V3:"/api/sdk/bestpath/split",ASSET_MINIMUM:"/api/sdk/asset/minimum"},Ht={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 Xt{constructor(e){this.config=e}static getInstance(e){if(!Xt.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}};Xt.instance=new Xt(t)}return Xt.instance}static resetInstance(){Xt.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 Tt({message:"Request timeout",code:Ht.API_ERROR,details:{endpoint:e,timeout:this.config.timeout}});throw new Tt({message:t.message,code:Ht.API_ERROR,details:{endpoint:e,originalError:t}})}throw new Tt({message:"Unknown API error",code:Ht.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(`${Kt.PATH_V3}?${o}`,{method:"GET"})}async getAssetMinimum(){return this.request(Kt.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("&")}}Xt.instance=null;let Zt=null;function Jt(){Zt=null,console.log("Minimum amounts cache cleared")}const en={3637:["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE","0x0D2437F93Fed6EA64Ef01cCde385FB1263910C56","0x29eE6138DD4C9815f46D34a4A1ed48F46758A402","0x9BC574a6f1170e90D80826D86a6126d59198A3Ef","0xA0b86a33E6441b8c4C8C0C4C0C4C0C4C0C4C0C4C","0xdAC17F958D2ee523a2206206994597C13D831ec7"],3636:["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE","0x233631132FD56c8f86D1FC97F0b82420a8d20af3","0xA0b86a33E6441b8c4C8C0C4C0C4C0C4C0C4C0C4C","0xdAC17F958D2ee523a2206206994597C13D831ec7"]};function tn(e,t){if(!e?.address)return!1;const n=en[t];return!!n&&n.some(t=>t.toLowerCase()===e.address.toLowerCase())}function nn(e,t,n,r=5){const s=tn(e,n),i=tn(t,n);return s&&i?r:1}async function rn(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(Zt&&n<Zt.expiresAt)return console.log("Using cached minimum amounts data"),Zt.data;console.log("Fetching fresh minimum amounts data from API");const r=Xt.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 Zt={data:s.data||[],timestamp:n,expiresAt:n+3e5},Zt.data}(s,i),c=a.find(t=>t.token?.toLowerCase()===e.address.toLowerCase()),u=a.find(e=>e.token?.toLowerCase()===t.address.toLowerCase()),l=new v(n);return c&&u&&l.gte(c.minimumAmount)&&l.gte(u.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"),nn(e,t,r,o))}catch(n){return console.warn("Failed to fetch online partCount data:",n),console.log("Falling back to offline partCount logic"),nn(e,t,r,o)}}async function sn(e,t,n,r,s,i=5,o){try{return await rn(e,t,n,r,s,o,i)}catch(e){return console.warn("Online partCount failed, using offline fallback:",e),i}}function on(e,t,n){if(0===t)return 1/0;return e/n/t*100}function an(e,t,n=5){return on(e,t,5)>n?1:5}function cn(e,t){return!e||isNaN(Number(e))?new v(0):new v(e).times(new v(10).pow(t))}function un(e,t){return new v(e).dividedBy(new v(10).pow(t)).toString()}function ln(e,t){return e.address.toLowerCase()===t.toLowerCase()}function fn(e,t){return e.address.toLowerCase()===t.toLowerCase()}function dn(e,t){return e&&t&&e.address&&t.address&&e.address!==t.address&&e.chainId===t.chainId}function hn(e){if(!e||isNaN(Number(e)))return!1;const t=new v(e);return t.gt(0)&&t.isFinite()}function pn(e,t,n=10){return new v(e).times(t).lt(1)?1:n}function gn(e){return"string"==typeof e?e:e?.message?e.message:e?.error?e.error:"Unknown error occurred"}function mn(e,t){let n;const r=(...r)=>{clearTimeout(n),n=setTimeout(()=>e(...r),t)};return r.cancel=()=>{clearTimeout(n)},r}const yn=[{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 bn{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(!dn(n,r))throw new Tt({message:"Invalid tokens provided",code:Ht.INVALID_TOKENS,details:{srcToken:n,dstToken:r}});if(!hn(t))throw new Tt({message:"Invalid amount provided",code:Ht.INVALID_AMOUNT,details:{amountIn:t}});const c=cn(t,n.decimals),{routerAddress:u,bitzyQueryAddress:l,wrappedAddress:f,nativeAddress:d}=this.config.config,h=ln(n,d),p=ln(r,d);if(h&&fn(r,f)||p&&fn(n,f)){const e=h?"wrap":"unwrap",t=c;return{routes:[[{routerAddress:u,lpAddress:zt,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:[c],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,c.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 v(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=ct([{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 v(0),o=[],u=[];if(this.config.publicClient)try{console.log("SDK: Calling splitQuery with:",{bitzyQueryAddress:l,amountIn:c.toFixed(0),partCount:a,encodedRoutesLength:s.length});const e=yt({abi:yn,functionName:"splitQuery",args:[c.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=ht({abi:t,args:n,name:r});if(!e)throw new k(r,{docsPath:$t});i=e}if("function"!==i.type)throw new k(void 0,{docsPath:$t});if(!i.outputs)throw new M(i.name,{docsPath:$t});const o=Ct(i.outputs,s);return o&&o.length>1?o:o&&1===o.length?o[0]:void 0}({abi:yn,functionName:"splitQuery",data:t.data}),n=e[1];if(n&&n.amountOut){i=new v(n.amountOut.toString());let e=n.distribution.map(e=>new v(e.toString()).toNumber());u=r.reduce((t,n,r)=>(e[r]>0&&t.push(n.map((e,t,n)=>({routerAddress:qt[e.source+"_"+e.type]||zt,lpAddress:e.pool||zt,fromToken:e.src,toToken:e.dest,from:t>0||"V3"===e.type||e.src===f.toLowerCase()?Ft:Rt,to:t<n.length-1||t===n.length-1&&e.dest===f.toLowerCase()?Ft:Rt,part:"100000000",amountAfterFee:new v(1e4).minus(new v(e.fee||0).dividedBy(100)).toFixed(),dexInterface:Ut[e.type]||0}))),t),[]),o=e.filter(e=>e>0)}}}catch(e){console.error("SDK: splitQuery contract call failed:",e),i=new v(0),o=[],u=[]}else console.error("SDK: No publicClient available - this is the problem!"),i=new v(0),o=[],u=[];const d=o.map(e=>i.times(e).dividedBy(a).dp(0,v.ROUND_DOWN)),h=o.map(e=>c.times(e).dividedBy(a).dp(0,v.ROUND_DOWN));return{routes:u,distributions:o,amountOutRoutes:d,amountOutBN:i,amountInParts:h,isAmountOutError:!1}}catch(t){throw new Tt({message:"Failed to fetch swap route",code:Ht.API_ERROR,details:{originalError:t,options:e}})}}getSupportedNetworks(){return Object.keys(Yt).map(Number)}getNetworkConfig(e){return this.config.config}getPartCount(e,t,n,r){return nn(e,t,n,r)}}async function wn(e,t={}){const{apiBaseUrl:n=kt,defaultPartCount:r=Lt,timeout:s=3e4,headers:i={}}=t,o=e.chainId,a=Gt(o);if(!a)throw new Error(`Unsupported network: ${o}`);const c=Xt.getInstance({baseUrl:n,timeout:s,headers:i});return new bn({config:{routerAddress:a.routerAddress,bitzyQueryAddress:a.bitzyQueryAddress,wrappedAddress:a.wrappedAddress,nativeAddress:a.nativeAddress},defaultPartCount:r,apiClient:c}).fetchRoute(e)}async function An(e){return(await Promise.allSettled(e.map(async({options:e,config:t})=>{try{return{success:!0,data:await wn(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"})}async function En(e,t,n,r,s={}){const i=await wn({amountIn:n,srcToken:e,dstToken:t,chainId:r},s);return{amountOut:i.amountOutBN.toFixed(0),routes:i.routes.length}}async function vn(e,t={}){const{types:n,enabledSources:r}=Wt(e.chainId);return wn({...e,types:n,enabledSources:r},{...t,forcePartCount:t.forcePartCount})}const In=(s,i,o,a,c={})=>{const u=e(()=>({}),[]),l=e(()=>({routerAddress:zt,bitzyQueryAddress:zt,wrappedAddress:zt,nativeAddress:zt}),[]),{apiBaseUrl:f,addressConfig:d,defaultPartCount:h,timeout:p,headers:g,refreshInterval:m,publicClient:y,configTypes:b,configEnabledSources:w,forcePartCount:A,useOnlinePartCount:E}=e(()=>{const{apiBaseUrl:e=kt,config:t=l,defaultPartCount:n=5,timeout:r=3e4,headers:s=u,refreshInterval:i=1e4,publicClient:o,types:a,enabledSources:f,forcePartCount:d,useOnlinePartCount:h=!1}=c;return{apiBaseUrl:e,addressConfig:t,defaultPartCount:n,timeout:r,headers:s,refreshInterval:i,publicClient:o,configTypes:a,configEnabledSources:f,forcePartCount:d,useOnlinePartCount:h}},[c,u,l]),I=e(()=>Wt(a),[a]),x=e(()=>b??I.types,[b,I.types]),C=e(()=>w??I.enabledSources,[w,I.enabledSources]);t(()=>{console.log("config",c)},[c]),t(()=>{console.log("srcToken",s)},[s]),t(()=>{console.log("dstToken",i)},[i]),t(()=>{console.log("amountIn",o)},[o]),t(()=>{console.log("chainId",a)},[a]),t(()=>{console.log("apiBaseUrl",f)},[f]),t(()=>{console.log("addressConfig",d)},[d]),t(()=>{console.log("defaultPartCount",h)},[h]),t(()=>{console.log("timeout",p)},[p]),t(()=>{console.log("headers",g)},[g]),t(()=>{console.log("types",x)},[x]),t(()=>{console.log("enabledSources",C)},[C]);const[P,O]=n(new v(0)),[B,N]=n([]),[$,z]=n([]),[D,S]=n([]),[T,U]=n([]),[R,F]=n(!1),[L,_]=n(!1),[k,M]=n(),[V,j]=n(!1),[W,G]=n(null),[Q,Y]=n(null),q=e(()=>(console.log("partCount",0,E),E?null!==Q?Q:nn(s,i,a,h):(console.log("partCount",1,A),void 0!==A?A:(console.log("partCount",2,h),nn(s,i,a,h)))),[h,A,E,Q,s,i,a]);t(()=>{if(!(E&&s&&i&&o))return void Y(null);(async()=>{try{const e=await sn(s,i,o,a,f,h);Y(e)}catch(e){console.warn("Failed to fetch online partCount:",e),Y(null)}})()},[E,s,i,o,a,f,h]);const K=e(()=>{const e=Gt(a),t=d&&Object.keys(d).length>0?d:{routerAddress:e?.routerAddress||"0x0000000000000000000000000000000000000000",bitzyQueryAddress:e?.bitzyQueryAddress||"0x0000000000000000000000000000000000000000",wrappedAddress:e?.wrappedAddress||"0x0000000000000000000000000000000000000000",nativeAddress:e?.nativeAddress||"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"},n=Xt.getInstance({baseUrl:f,timeout:p,headers:g});return new bn({config:t,defaultPartCount:h,apiClient:n,publicClient:y})},[d,h,f,p,g,y,a]),H=r(()=>{G(null)},[]),X=r(async()=>{if(!s||!i||!o||"0"===o)return O(new v(0)),N([]),z([]),S([]),U([]),_(!1),j(!1),void G(null);F(!0),G(null);try{const e={amountIn:o,srcToken:s,dstToken:i,chainId:a,partCount:q,types:x,enabledSources:C},t=await K.fetchRoute(e);O(t.amountOutBN),N(t.routes),z(t.distributions),S(t.amountOutRoutes),U(t.amountInParts),_(t.isAmountOutError),M(t.isWrap),j(!0)}catch(e){const t=e instanceof Error?e.message:"Unknown error occurred";G(t),console.error("Error fetching route:",e),O(new v(0)),N([]),z([]),S([]),U([]),_(!0),j(!1)}finally{F(!1)}},[K,s,i,o,a,q,x,C]),Z=e(()=>mn(X,300),[X]);return t(()=>{if(!o||"0"===o)return O(new v(0)),N([]),z([]),S([]),U([]),_(!1),j(!1),void G(null);Z();const e=setInterval(()=>{Z()},m);return()=>{clearInterval(e),"function"==typeof Z.cancel&&Z.cancel()}},[o,s?.address,i?.address,Z,m]),t(()=>{V&&X()},[X,V,K]),{routes:B,distributions:$,amountOutRoutes:D,amountOutBN:P,amountInParts:T,fetchRoute:X,isLoading:R,isAmountOutError:L,isFirstFetch:V,isWrap:k,error:W,clearError:H}};export{Xt as APIClient,Kt as API_ENDPOINTS,yn as BITZY_QUERY_ABI,Vt as CONTRACT_ADDRESSES,Yt as DEFAULT_NETWORKS,Lt as DEFAULT_PART_COUNT,_t as DEFAULT_TIMEOUT,Ut as DEX_INTERFACE,qt as DEX_ROUTER,Mt as DEX_ROUTERS,Ht as ERROR_CODES,en as HIGH_VALUE_TOKENS,jt as LIQUIDITY_SOURCES,Ft as ROUTER_TARGET,bn as SwapV3Service,Rt as USER_TARGET,pn as calculatePartCount,on as calculatePriceImpact,Jt as clearMinimumAmountsCache,mn as debounce,Dt as ensureBigNumber,An as fetchBatchSwapRoutes,wn as fetchSwapRoute,vn as fetchSwapRouteSimple,gn as formatError,cn as fromTokenAmount,Gt as getContractAddresses,Qt as getDexRouters,Wt as getLiquiditySources,an as getOptimalPartCount,nn as getPartCountOffline,rn as getPartCountOnline,sn as getPartCountWithFallback,En as getSwapQuote,wn as getSwapRoute,St as isBigNumber,tn as isHighValueToken,ln as isNativeToken,fn as isWrappedToken,un as toTokenAmount,In as useSwapRoutes,In as useSwapV3Routes,hn as validateAmount,dn as validateTokens};
|
|
2
4
|
//# sourceMappingURL=index.esm.js.map
|