@cetusprotocol/dlmm-zap-sdk 0.0.1 → 1.0.0
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/README.md +243 -72
- package/dist/index.d.mts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var Wi=Object.create;var It=Object.defineProperty;var Ui=Object.getOwnPropertyDescriptor;var zi=Object.getOwnPropertyNames;var Hi=Object.getPrototypeOf,Vi=Object.prototype.hasOwnProperty;var Ji=(S,m)=>()=>(m||S((m={exports:{}}).exports,m),m.exports),Qi=(S,m)=>{for(var d in m)It(S,d,{get:m[d],enumerable:!0})},Pi=(S,m,d,g)=>{if(m&&typeof m=="object"||typeof m=="function")for(let f of zi(m))!Vi.call(S,f)&&f!==d&&It(S,f,{get:()=>m[f],enumerable:!(g=Ui(m,f))||g.enumerable});return S};var Ti=(S,m,d)=>(d=S!=null?Wi(Hi(S)):{},Pi(m||!S||!S.__esModule?It(d,"default",{value:S,enumerable:!0}):d,S)),Xi=S=>Pi(It({},"__esModule",{value:!0}),S);var li=Ji((Ii,fi)=>{"use strict";(function(S,m){"use strict";function d(h,t){if(!h)throw new Error(t||"Assertion failed")}function g(h,t){h.super_=t;var r=function(){};r.prototype=t.prototype,h.prototype=new r,h.prototype.constructor=h}function f(h,t,r){if(f.isBN(h))return h;this.negative=0,this.words=null,this.length=0,this.red=null,h!==null&&((t==="le"||t==="be")&&(r=t,t=10),this._init(h||0,t||10,r||"be"))}typeof S=="object"?S.exports=f:m.BN=f,f.BN=f,f.wordSize=26;var A;try{typeof window<"u"&&typeof window.Buffer<"u"?A=window.Buffer:A=require("buffer").Buffer}catch{}f.isBN=function(t){return t instanceof f?!0:t!==null&&typeof t=="object"&&t.constructor.wordSize===f.wordSize&&Array.isArray(t.words)},f.max=function(t,r){return t.cmp(r)>0?t:r},f.min=function(t,r){return t.cmp(r)<0?t:r},f.prototype._init=function(t,r,e){if(typeof t=="number")return this._initNumber(t,r,e);if(typeof t=="object")return this._initArray(t,r,e);r==="hex"&&(r=16),d(r===(r|0)&&r>=2&&r<=36),t=t.toString().replace(/\s+/g,"");var n=0;t[0]==="-"&&(n++,this.negative=1),n<t.length&&(r===16?this._parseHex(t,n,e):(this._parseBase(t,r,n),e==="le"&&this._initArray(this.toArray(),r,e)))},f.prototype._initNumber=function(t,r,e){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[t&67108863],this.length=1):t<4503599627370496?(this.words=[t&67108863,t/67108864&67108863],this.length=2):(d(t<9007199254740992),this.words=[t&67108863,t/67108864&67108863,1],this.length=3),e==="le"&&this._initArray(this.toArray(),r,e)},f.prototype._initArray=function(t,r,e){if(d(typeof t.length=="number"),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var s,l,u=0;if(e==="be")for(n=t.length-1,s=0;n>=0;n-=3)l=t[n]|t[n-1]<<8|t[n-2]<<16,this.words[s]|=l<<u&67108863,this.words[s+1]=l>>>26-u&67108863,u+=24,u>=26&&(u-=26,s++);else if(e==="le")for(n=0,s=0;n<t.length;n+=3)l=t[n]|t[n+1]<<8|t[n+2]<<16,this.words[s]|=l<<u&67108863,this.words[s+1]=l>>>26-u&67108863,u+=24,u>=26&&(u-=26,s++);return this._strip()};function w(h,t){var r=h.charCodeAt(t);if(r>=48&&r<=57)return r-48;if(r>=65&&r<=70)return r-55;if(r>=97&&r<=102)return r-87;d(!1,"Invalid character in "+h)}function _(h,t,r){var e=w(h,r);return r-1>=t&&(e|=w(h,r-1)<<4),e}f.prototype._parseHex=function(t,r,e){this.length=Math.ceil((t.length-r)/6),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var s=0,l=0,u;if(e==="be")for(n=t.length-1;n>=r;n-=2)u=_(t,r,n)<<s,this.words[l]|=u&67108863,s>=18?(s-=18,l+=1,this.words[l]|=u>>>26):s+=8;else{var o=t.length-r;for(n=o%2===0?r+1:r;n<t.length;n+=2)u=_(t,r,n)<<s,this.words[l]|=u&67108863,s>=18?(s-=18,l+=1,this.words[l]|=u>>>26):s+=8}this._strip()};function y(h,t,r,e){for(var n=0,s=0,l=Math.min(h.length,r),u=t;u<l;u++){var o=h.charCodeAt(u)-48;n*=e,o>=49?s=o-49+10:o>=17?s=o-17+10:s=o,d(o>=0&&s<e,"Invalid character"),n+=s}return n}f.prototype._parseBase=function(t,r,e){this.words=[0],this.length=1;for(var n=0,s=1;s<=67108863;s*=r)n++;n--,s=s/r|0;for(var l=t.length-e,u=l%n,o=Math.min(l,l-u)+e,i=0,a=e;a<o;a+=n)i=y(t,a,a+n,r),this.imuln(s),this.words[0]+i<67108864?this.words[0]+=i:this._iaddn(i);if(u!==0){var p=1;for(i=y(t,a,t.length,r),a=0;a<u;a++)p*=r;this.imuln(p),this.words[0]+i<67108864?this.words[0]+=i:this._iaddn(i)}this._strip()},f.prototype.copy=function(t){t.words=new Array(this.length);for(var r=0;r<this.length;r++)t.words[r]=this.words[r];t.length=this.length,t.negative=this.negative,t.red=this.red};function b(h,t){h.words=t.words,h.length=t.length,h.negative=t.negative,h.red=t.red}if(f.prototype._move=function(t){b(t,this)},f.prototype.clone=function(){var t=new f(null);return this.copy(t),t},f.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},f.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},f.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{f.prototype[Symbol.for("nodejs.util.inspect.custom")]=D}catch{f.prototype.inspect=D}else f.prototype.inspect=D;function D(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var B=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],K=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],k=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];f.prototype.toString=function(t,r){t=t||10,r=r|0||1;var e;if(t===16||t==="hex"){e="";for(var n=0,s=0,l=0;l<this.length;l++){var u=this.words[l],o=((u<<n|s)&16777215).toString(16);s=u>>>24-n&16777215,n+=2,n>=26&&(n-=26,l--),s!==0||l!==this.length-1?e=B[6-o.length]+o+e:e=o+e}for(s!==0&&(e=s.toString(16)+e);e.length%r!==0;)e="0"+e;return this.negative!==0&&(e="-"+e),e}if(t===(t|0)&&t>=2&&t<=36){var i=K[t],a=k[t];e="";var p=this.clone();for(p.negative=0;!p.isZero();){var c=p.modrn(a).toString(t);p=p.idivn(a),p.isZero()?e=c+e:e=B[i-c.length]+c+e}for(this.isZero()&&(e="0"+e);e.length%r!==0;)e="0"+e;return this.negative!==0&&(e="-"+e),e}d(!1,"Base should be between 2 and 36")},f.prototype.toNumber=function(){var t=this.words[0];return this.length===2?t+=this.words[1]*67108864:this.length===3&&this.words[2]===1?t+=4503599627370496+this.words[1]*67108864:this.length>2&&d(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-t:t},f.prototype.toJSON=function(){return this.toString(16,2)},A&&(f.prototype.toBuffer=function(t,r){return this.toArrayLike(A,t,r)}),f.prototype.toArray=function(t,r){return this.toArrayLike(Array,t,r)};var E=function(t,r){return t.allocUnsafe?t.allocUnsafe(r):new t(r)};f.prototype.toArrayLike=function(t,r,e){this._strip();var n=this.byteLength(),s=e||Math.max(1,n);d(n<=s,"byte array longer than desired length"),d(s>0,"Requested array length <= 0");var l=E(t,s),u=r==="le"?"LE":"BE";return this["_toArrayLike"+u](l,n),l},f.prototype._toArrayLikeLE=function(t,r){for(var e=0,n=0,s=0,l=0;s<this.length;s++){var u=this.words[s]<<l|n;t[e++]=u&255,e<t.length&&(t[e++]=u>>8&255),e<t.length&&(t[e++]=u>>16&255),l===6?(e<t.length&&(t[e++]=u>>24&255),n=0,l=0):(n=u>>>24,l+=2)}if(e<t.length)for(t[e++]=n;e<t.length;)t[e++]=0},f.prototype._toArrayLikeBE=function(t,r){for(var e=t.length-1,n=0,s=0,l=0;s<this.length;s++){var u=this.words[s]<<l|n;t[e--]=u&255,e>=0&&(t[e--]=u>>8&255),e>=0&&(t[e--]=u>>16&255),l===6?(e>=0&&(t[e--]=u>>24&255),n=0,l=0):(n=u>>>24,l+=2)}if(e>=0)for(t[e--]=n;e>=0;)t[e--]=0},Math.clz32?f.prototype._countBits=function(t){return 32-Math.clz32(t)}:f.prototype._countBits=function(t){var r=t,e=0;return r>=4096&&(e+=13,r>>>=13),r>=64&&(e+=7,r>>>=7),r>=8&&(e+=4,r>>>=4),r>=2&&(e+=2,r>>>=2),e+r},f.prototype._zeroBits=function(t){if(t===0)return 26;var r=t,e=0;return(r&8191)===0&&(e+=13,r>>>=13),(r&127)===0&&(e+=7,r>>>=7),(r&15)===0&&(e+=4,r>>>=4),(r&3)===0&&(e+=2,r>>>=2),(r&1)===0&&e++,e},f.prototype.bitLength=function(){var t=this.words[this.length-1],r=this._countBits(t);return(this.length-1)*26+r};function W(h){for(var t=new Array(h.bitLength()),r=0;r<t.length;r++){var e=r/26|0,n=r%26;t[r]=h.words[e]>>>n&1}return t}f.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,r=0;r<this.length;r++){var e=this._zeroBits(this.words[r]);if(t+=e,e!==26)break}return t},f.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},f.prototype.toTwos=function(t){return this.negative!==0?this.abs().inotn(t).iaddn(1):this.clone()},f.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},f.prototype.isNeg=function(){return this.negative!==0},f.prototype.neg=function(){return this.clone().ineg()},f.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},f.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var r=0;r<t.length;r++)this.words[r]=this.words[r]|t.words[r];return this._strip()},f.prototype.ior=function(t){return d((this.negative|t.negative)===0),this.iuor(t)},f.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},f.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},f.prototype.iuand=function(t){var r;this.length>t.length?r=t:r=this;for(var e=0;e<r.length;e++)this.words[e]=this.words[e]&t.words[e];return this.length=r.length,this._strip()},f.prototype.iand=function(t){return d((this.negative|t.negative)===0),this.iuand(t)},f.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},f.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},f.prototype.iuxor=function(t){var r,e;this.length>t.length?(r=this,e=t):(r=t,e=this);for(var n=0;n<e.length;n++)this.words[n]=r.words[n]^e.words[n];if(this!==r)for(;n<r.length;n++)this.words[n]=r.words[n];return this.length=r.length,this._strip()},f.prototype.ixor=function(t){return d((this.negative|t.negative)===0),this.iuxor(t)},f.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},f.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},f.prototype.inotn=function(t){d(typeof t=="number"&&t>=0);var r=Math.ceil(t/26)|0,e=t%26;this._expand(r),e>0&&r--;for(var n=0;n<r;n++)this.words[n]=~this.words[n]&67108863;return e>0&&(this.words[n]=~this.words[n]&67108863>>26-e),this._strip()},f.prototype.notn=function(t){return this.clone().inotn(t)},f.prototype.setn=function(t,r){d(typeof t=="number"&&t>=0);var e=t/26|0,n=t%26;return this._expand(e+1),r?this.words[e]=this.words[e]|1<<n:this.words[e]=this.words[e]&~(1<<n),this._strip()},f.prototype.iadd=function(t){var r;if(this.negative!==0&&t.negative===0)return this.negative=0,r=this.isub(t),this.negative^=1,this._normSign();if(this.negative===0&&t.negative!==0)return t.negative=0,r=this.isub(t),t.negative=1,r._normSign();var e,n;this.length>t.length?(e=this,n=t):(e=t,n=this);for(var s=0,l=0;l<n.length;l++)r=(e.words[l]|0)+(n.words[l]|0)+s,this.words[l]=r&67108863,s=r>>>26;for(;s!==0&&l<e.length;l++)r=(e.words[l]|0)+s,this.words[l]=r&67108863,s=r>>>26;if(this.length=e.length,s!==0)this.words[this.length]=s,this.length++;else if(e!==this)for(;l<e.length;l++)this.words[l]=e.words[l];return this},f.prototype.add=function(t){var r;return t.negative!==0&&this.negative===0?(t.negative=0,r=this.sub(t),t.negative^=1,r):t.negative===0&&this.negative!==0?(this.negative=0,r=t.sub(this),this.negative=1,r):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},f.prototype.isub=function(t){if(t.negative!==0){t.negative=0;var r=this.iadd(t);return t.negative=1,r._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var e=this.cmp(t);if(e===0)return this.negative=0,this.length=1,this.words[0]=0,this;var n,s;e>0?(n=this,s=t):(n=t,s=this);for(var l=0,u=0;u<s.length;u++)r=(n.words[u]|0)-(s.words[u]|0)+l,l=r>>26,this.words[u]=r&67108863;for(;l!==0&&u<n.length;u++)r=(n.words[u]|0)+l,l=r>>26,this.words[u]=r&67108863;if(l===0&&u<n.length&&n!==this)for(;u<n.length;u++)this.words[u]=n.words[u];return this.length=Math.max(this.length,u),n!==this&&(this.negative=1),this._strip()},f.prototype.sub=function(t){return this.clone().isub(t)};function bt(h,t,r){r.negative=t.negative^h.negative;var e=h.length+t.length|0;r.length=e,e=e-1|0;var n=h.words[0]|0,s=t.words[0]|0,l=n*s,u=l&67108863,o=l/67108864|0;r.words[0]=u;for(var i=1;i<e;i++){for(var a=o>>>26,p=o&67108863,c=Math.min(i,t.length-1),v=Math.max(0,i-h.length+1);v<=c;v++){var x=i-v|0;n=h.words[x]|0,s=t.words[v]|0,l=n*s+p,a+=l/67108864|0,p=l&67108863}r.words[i]=p|0,o=a|0}return o!==0?r.words[i]=o|0:r.length--,r._strip()}var N=function(t,r,e){var n=t.words,s=r.words,l=e.words,u=0,o,i,a,p=n[0]|0,c=p&8191,v=p>>>13,x=n[1]|0,O=x&8191,I=x>>>13,Ot=n[2]|0,F=Ot&8191,Z=Ot>>>13,_i=n[3]|0,U=_i&8191,z=_i>>>13,Mi=n[4]|0,H=Mi&8191,V=Mi>>>13,wi=n[5]|0,J=wi&8191,Q=wi>>>13,yi=n[6]|0,X=yi&8191,Y=yi>>>13,xi=n[7]|0,$=xi&8191,G=xi>>>13,bi=n[8]|0,j=bi&8191,tt=bi>>>13,Si=n[9]|0,it=Si&8191,rt=Si>>>13,Ai=s[0]|0,et=Ai&8191,nt=Ai>>>13,Di=s[1]|0,ot=Di&8191,st=Di>>>13,Ri=s[2]|0,at=Ri&8191,ht=Ri>>>13,Bi=s[3]|0,ft=Bi&8191,lt=Bi>>>13,Oi=s[4]|0,ut=Oi&8191,dt=Oi>>>13,ki=s[5]|0,mt=ki&8191,pt=ki>>>13,qi=s[6]|0,ct=qi&8191,vt=qi>>>13,Ci=s[7]|0,gt=Ci&8191,_t=Ci>>>13,Li=s[8]|0,Mt=Li&8191,wt=Li>>>13,Ei=s[9]|0,yt=Ei&8191,xt=Ei>>>13;e.negative=t.negative^r.negative,e.length=19,o=Math.imul(c,et),i=Math.imul(c,nt),i=i+Math.imul(v,et)|0,a=Math.imul(v,nt);var Wt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Wt>>>26)|0,Wt&=67108863,o=Math.imul(O,et),i=Math.imul(O,nt),i=i+Math.imul(I,et)|0,a=Math.imul(I,nt),o=o+Math.imul(c,ot)|0,i=i+Math.imul(c,st)|0,i=i+Math.imul(v,ot)|0,a=a+Math.imul(v,st)|0;var Ut=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Ut>>>26)|0,Ut&=67108863,o=Math.imul(F,et),i=Math.imul(F,nt),i=i+Math.imul(Z,et)|0,a=Math.imul(Z,nt),o=o+Math.imul(O,ot)|0,i=i+Math.imul(O,st)|0,i=i+Math.imul(I,ot)|0,a=a+Math.imul(I,st)|0,o=o+Math.imul(c,at)|0,i=i+Math.imul(c,ht)|0,i=i+Math.imul(v,at)|0,a=a+Math.imul(v,ht)|0;var zt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(zt>>>26)|0,zt&=67108863,o=Math.imul(U,et),i=Math.imul(U,nt),i=i+Math.imul(z,et)|0,a=Math.imul(z,nt),o=o+Math.imul(F,ot)|0,i=i+Math.imul(F,st)|0,i=i+Math.imul(Z,ot)|0,a=a+Math.imul(Z,st)|0,o=o+Math.imul(O,at)|0,i=i+Math.imul(O,ht)|0,i=i+Math.imul(I,at)|0,a=a+Math.imul(I,ht)|0,o=o+Math.imul(c,ft)|0,i=i+Math.imul(c,lt)|0,i=i+Math.imul(v,ft)|0,a=a+Math.imul(v,lt)|0;var Ht=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Ht>>>26)|0,Ht&=67108863,o=Math.imul(H,et),i=Math.imul(H,nt),i=i+Math.imul(V,et)|0,a=Math.imul(V,nt),o=o+Math.imul(U,ot)|0,i=i+Math.imul(U,st)|0,i=i+Math.imul(z,ot)|0,a=a+Math.imul(z,st)|0,o=o+Math.imul(F,at)|0,i=i+Math.imul(F,ht)|0,i=i+Math.imul(Z,at)|0,a=a+Math.imul(Z,ht)|0,o=o+Math.imul(O,ft)|0,i=i+Math.imul(O,lt)|0,i=i+Math.imul(I,ft)|0,a=a+Math.imul(I,lt)|0,o=o+Math.imul(c,ut)|0,i=i+Math.imul(c,dt)|0,i=i+Math.imul(v,ut)|0,a=a+Math.imul(v,dt)|0;var Vt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Vt>>>26)|0,Vt&=67108863,o=Math.imul(J,et),i=Math.imul(J,nt),i=i+Math.imul(Q,et)|0,a=Math.imul(Q,nt),o=o+Math.imul(H,ot)|0,i=i+Math.imul(H,st)|0,i=i+Math.imul(V,ot)|0,a=a+Math.imul(V,st)|0,o=o+Math.imul(U,at)|0,i=i+Math.imul(U,ht)|0,i=i+Math.imul(z,at)|0,a=a+Math.imul(z,ht)|0,o=o+Math.imul(F,ft)|0,i=i+Math.imul(F,lt)|0,i=i+Math.imul(Z,ft)|0,a=a+Math.imul(Z,lt)|0,o=o+Math.imul(O,ut)|0,i=i+Math.imul(O,dt)|0,i=i+Math.imul(I,ut)|0,a=a+Math.imul(I,dt)|0,o=o+Math.imul(c,mt)|0,i=i+Math.imul(c,pt)|0,i=i+Math.imul(v,mt)|0,a=a+Math.imul(v,pt)|0;var Jt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Jt>>>26)|0,Jt&=67108863,o=Math.imul(X,et),i=Math.imul(X,nt),i=i+Math.imul(Y,et)|0,a=Math.imul(Y,nt),o=o+Math.imul(J,ot)|0,i=i+Math.imul(J,st)|0,i=i+Math.imul(Q,ot)|0,a=a+Math.imul(Q,st)|0,o=o+Math.imul(H,at)|0,i=i+Math.imul(H,ht)|0,i=i+Math.imul(V,at)|0,a=a+Math.imul(V,ht)|0,o=o+Math.imul(U,ft)|0,i=i+Math.imul(U,lt)|0,i=i+Math.imul(z,ft)|0,a=a+Math.imul(z,lt)|0,o=o+Math.imul(F,ut)|0,i=i+Math.imul(F,dt)|0,i=i+Math.imul(Z,ut)|0,a=a+Math.imul(Z,dt)|0,o=o+Math.imul(O,mt)|0,i=i+Math.imul(O,pt)|0,i=i+Math.imul(I,mt)|0,a=a+Math.imul(I,pt)|0,o=o+Math.imul(c,ct)|0,i=i+Math.imul(c,vt)|0,i=i+Math.imul(v,ct)|0,a=a+Math.imul(v,vt)|0;var Qt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,o=Math.imul($,et),i=Math.imul($,nt),i=i+Math.imul(G,et)|0,a=Math.imul(G,nt),o=o+Math.imul(X,ot)|0,i=i+Math.imul(X,st)|0,i=i+Math.imul(Y,ot)|0,a=a+Math.imul(Y,st)|0,o=o+Math.imul(J,at)|0,i=i+Math.imul(J,ht)|0,i=i+Math.imul(Q,at)|0,a=a+Math.imul(Q,ht)|0,o=o+Math.imul(H,ft)|0,i=i+Math.imul(H,lt)|0,i=i+Math.imul(V,ft)|0,a=a+Math.imul(V,lt)|0,o=o+Math.imul(U,ut)|0,i=i+Math.imul(U,dt)|0,i=i+Math.imul(z,ut)|0,a=a+Math.imul(z,dt)|0,o=o+Math.imul(F,mt)|0,i=i+Math.imul(F,pt)|0,i=i+Math.imul(Z,mt)|0,a=a+Math.imul(Z,pt)|0,o=o+Math.imul(O,ct)|0,i=i+Math.imul(O,vt)|0,i=i+Math.imul(I,ct)|0,a=a+Math.imul(I,vt)|0,o=o+Math.imul(c,gt)|0,i=i+Math.imul(c,_t)|0,i=i+Math.imul(v,gt)|0,a=a+Math.imul(v,_t)|0;var Xt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Xt>>>26)|0,Xt&=67108863,o=Math.imul(j,et),i=Math.imul(j,nt),i=i+Math.imul(tt,et)|0,a=Math.imul(tt,nt),o=o+Math.imul($,ot)|0,i=i+Math.imul($,st)|0,i=i+Math.imul(G,ot)|0,a=a+Math.imul(G,st)|0,o=o+Math.imul(X,at)|0,i=i+Math.imul(X,ht)|0,i=i+Math.imul(Y,at)|0,a=a+Math.imul(Y,ht)|0,o=o+Math.imul(J,ft)|0,i=i+Math.imul(J,lt)|0,i=i+Math.imul(Q,ft)|0,a=a+Math.imul(Q,lt)|0,o=o+Math.imul(H,ut)|0,i=i+Math.imul(H,dt)|0,i=i+Math.imul(V,ut)|0,a=a+Math.imul(V,dt)|0,o=o+Math.imul(U,mt)|0,i=i+Math.imul(U,pt)|0,i=i+Math.imul(z,mt)|0,a=a+Math.imul(z,pt)|0,o=o+Math.imul(F,ct)|0,i=i+Math.imul(F,vt)|0,i=i+Math.imul(Z,ct)|0,a=a+Math.imul(Z,vt)|0,o=o+Math.imul(O,gt)|0,i=i+Math.imul(O,_t)|0,i=i+Math.imul(I,gt)|0,a=a+Math.imul(I,_t)|0,o=o+Math.imul(c,Mt)|0,i=i+Math.imul(c,wt)|0,i=i+Math.imul(v,Mt)|0,a=a+Math.imul(v,wt)|0;var Yt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Yt>>>26)|0,Yt&=67108863,o=Math.imul(it,et),i=Math.imul(it,nt),i=i+Math.imul(rt,et)|0,a=Math.imul(rt,nt),o=o+Math.imul(j,ot)|0,i=i+Math.imul(j,st)|0,i=i+Math.imul(tt,ot)|0,a=a+Math.imul(tt,st)|0,o=o+Math.imul($,at)|0,i=i+Math.imul($,ht)|0,i=i+Math.imul(G,at)|0,a=a+Math.imul(G,ht)|0,o=o+Math.imul(X,ft)|0,i=i+Math.imul(X,lt)|0,i=i+Math.imul(Y,ft)|0,a=a+Math.imul(Y,lt)|0,o=o+Math.imul(J,ut)|0,i=i+Math.imul(J,dt)|0,i=i+Math.imul(Q,ut)|0,a=a+Math.imul(Q,dt)|0,o=o+Math.imul(H,mt)|0,i=i+Math.imul(H,pt)|0,i=i+Math.imul(V,mt)|0,a=a+Math.imul(V,pt)|0,o=o+Math.imul(U,ct)|0,i=i+Math.imul(U,vt)|0,i=i+Math.imul(z,ct)|0,a=a+Math.imul(z,vt)|0,o=o+Math.imul(F,gt)|0,i=i+Math.imul(F,_t)|0,i=i+Math.imul(Z,gt)|0,a=a+Math.imul(Z,_t)|0,o=o+Math.imul(O,Mt)|0,i=i+Math.imul(O,wt)|0,i=i+Math.imul(I,Mt)|0,a=a+Math.imul(I,wt)|0,o=o+Math.imul(c,yt)|0,i=i+Math.imul(c,xt)|0,i=i+Math.imul(v,yt)|0,a=a+Math.imul(v,xt)|0;var $t=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+($t>>>26)|0,$t&=67108863,o=Math.imul(it,ot),i=Math.imul(it,st),i=i+Math.imul(rt,ot)|0,a=Math.imul(rt,st),o=o+Math.imul(j,at)|0,i=i+Math.imul(j,ht)|0,i=i+Math.imul(tt,at)|0,a=a+Math.imul(tt,ht)|0,o=o+Math.imul($,ft)|0,i=i+Math.imul($,lt)|0,i=i+Math.imul(G,ft)|0,a=a+Math.imul(G,lt)|0,o=o+Math.imul(X,ut)|0,i=i+Math.imul(X,dt)|0,i=i+Math.imul(Y,ut)|0,a=a+Math.imul(Y,dt)|0,o=o+Math.imul(J,mt)|0,i=i+Math.imul(J,pt)|0,i=i+Math.imul(Q,mt)|0,a=a+Math.imul(Q,pt)|0,o=o+Math.imul(H,ct)|0,i=i+Math.imul(H,vt)|0,i=i+Math.imul(V,ct)|0,a=a+Math.imul(V,vt)|0,o=o+Math.imul(U,gt)|0,i=i+Math.imul(U,_t)|0,i=i+Math.imul(z,gt)|0,a=a+Math.imul(z,_t)|0,o=o+Math.imul(F,Mt)|0,i=i+Math.imul(F,wt)|0,i=i+Math.imul(Z,Mt)|0,a=a+Math.imul(Z,wt)|0,o=o+Math.imul(O,yt)|0,i=i+Math.imul(O,xt)|0,i=i+Math.imul(I,yt)|0,a=a+Math.imul(I,xt)|0;var Gt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Gt>>>26)|0,Gt&=67108863,o=Math.imul(it,at),i=Math.imul(it,ht),i=i+Math.imul(rt,at)|0,a=Math.imul(rt,ht),o=o+Math.imul(j,ft)|0,i=i+Math.imul(j,lt)|0,i=i+Math.imul(tt,ft)|0,a=a+Math.imul(tt,lt)|0,o=o+Math.imul($,ut)|0,i=i+Math.imul($,dt)|0,i=i+Math.imul(G,ut)|0,a=a+Math.imul(G,dt)|0,o=o+Math.imul(X,mt)|0,i=i+Math.imul(X,pt)|0,i=i+Math.imul(Y,mt)|0,a=a+Math.imul(Y,pt)|0,o=o+Math.imul(J,ct)|0,i=i+Math.imul(J,vt)|0,i=i+Math.imul(Q,ct)|0,a=a+Math.imul(Q,vt)|0,o=o+Math.imul(H,gt)|0,i=i+Math.imul(H,_t)|0,i=i+Math.imul(V,gt)|0,a=a+Math.imul(V,_t)|0,o=o+Math.imul(U,Mt)|0,i=i+Math.imul(U,wt)|0,i=i+Math.imul(z,Mt)|0,a=a+Math.imul(z,wt)|0,o=o+Math.imul(F,yt)|0,i=i+Math.imul(F,xt)|0,i=i+Math.imul(Z,yt)|0,a=a+Math.imul(Z,xt)|0;var jt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(jt>>>26)|0,jt&=67108863,o=Math.imul(it,ft),i=Math.imul(it,lt),i=i+Math.imul(rt,ft)|0,a=Math.imul(rt,lt),o=o+Math.imul(j,ut)|0,i=i+Math.imul(j,dt)|0,i=i+Math.imul(tt,ut)|0,a=a+Math.imul(tt,dt)|0,o=o+Math.imul($,mt)|0,i=i+Math.imul($,pt)|0,i=i+Math.imul(G,mt)|0,a=a+Math.imul(G,pt)|0,o=o+Math.imul(X,ct)|0,i=i+Math.imul(X,vt)|0,i=i+Math.imul(Y,ct)|0,a=a+Math.imul(Y,vt)|0,o=o+Math.imul(J,gt)|0,i=i+Math.imul(J,_t)|0,i=i+Math.imul(Q,gt)|0,a=a+Math.imul(Q,_t)|0,o=o+Math.imul(H,Mt)|0,i=i+Math.imul(H,wt)|0,i=i+Math.imul(V,Mt)|0,a=a+Math.imul(V,wt)|0,o=o+Math.imul(U,yt)|0,i=i+Math.imul(U,xt)|0,i=i+Math.imul(z,yt)|0,a=a+Math.imul(z,xt)|0;var ti=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(ti>>>26)|0,ti&=67108863,o=Math.imul(it,ut),i=Math.imul(it,dt),i=i+Math.imul(rt,ut)|0,a=Math.imul(rt,dt),o=o+Math.imul(j,mt)|0,i=i+Math.imul(j,pt)|0,i=i+Math.imul(tt,mt)|0,a=a+Math.imul(tt,pt)|0,o=o+Math.imul($,ct)|0,i=i+Math.imul($,vt)|0,i=i+Math.imul(G,ct)|0,a=a+Math.imul(G,vt)|0,o=o+Math.imul(X,gt)|0,i=i+Math.imul(X,_t)|0,i=i+Math.imul(Y,gt)|0,a=a+Math.imul(Y,_t)|0,o=o+Math.imul(J,Mt)|0,i=i+Math.imul(J,wt)|0,i=i+Math.imul(Q,Mt)|0,a=a+Math.imul(Q,wt)|0,o=o+Math.imul(H,yt)|0,i=i+Math.imul(H,xt)|0,i=i+Math.imul(V,yt)|0,a=a+Math.imul(V,xt)|0;var ii=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(ii>>>26)|0,ii&=67108863,o=Math.imul(it,mt),i=Math.imul(it,pt),i=i+Math.imul(rt,mt)|0,a=Math.imul(rt,pt),o=o+Math.imul(j,ct)|0,i=i+Math.imul(j,vt)|0,i=i+Math.imul(tt,ct)|0,a=a+Math.imul(tt,vt)|0,o=o+Math.imul($,gt)|0,i=i+Math.imul($,_t)|0,i=i+Math.imul(G,gt)|0,a=a+Math.imul(G,_t)|0,o=o+Math.imul(X,Mt)|0,i=i+Math.imul(X,wt)|0,i=i+Math.imul(Y,Mt)|0,a=a+Math.imul(Y,wt)|0,o=o+Math.imul(J,yt)|0,i=i+Math.imul(J,xt)|0,i=i+Math.imul(Q,yt)|0,a=a+Math.imul(Q,xt)|0;var ri=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(ri>>>26)|0,ri&=67108863,o=Math.imul(it,ct),i=Math.imul(it,vt),i=i+Math.imul(rt,ct)|0,a=Math.imul(rt,vt),o=o+Math.imul(j,gt)|0,i=i+Math.imul(j,_t)|0,i=i+Math.imul(tt,gt)|0,a=a+Math.imul(tt,_t)|0,o=o+Math.imul($,Mt)|0,i=i+Math.imul($,wt)|0,i=i+Math.imul(G,Mt)|0,a=a+Math.imul(G,wt)|0,o=o+Math.imul(X,yt)|0,i=i+Math.imul(X,xt)|0,i=i+Math.imul(Y,yt)|0,a=a+Math.imul(Y,xt)|0;var ei=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(ei>>>26)|0,ei&=67108863,o=Math.imul(it,gt),i=Math.imul(it,_t),i=i+Math.imul(rt,gt)|0,a=Math.imul(rt,_t),o=o+Math.imul(j,Mt)|0,i=i+Math.imul(j,wt)|0,i=i+Math.imul(tt,Mt)|0,a=a+Math.imul(tt,wt)|0,o=o+Math.imul($,yt)|0,i=i+Math.imul($,xt)|0,i=i+Math.imul(G,yt)|0,a=a+Math.imul(G,xt)|0;var ni=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(ni>>>26)|0,ni&=67108863,o=Math.imul(it,Mt),i=Math.imul(it,wt),i=i+Math.imul(rt,Mt)|0,a=Math.imul(rt,wt),o=o+Math.imul(j,yt)|0,i=i+Math.imul(j,xt)|0,i=i+Math.imul(tt,yt)|0,a=a+Math.imul(tt,xt)|0;var oi=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(oi>>>26)|0,oi&=67108863,o=Math.imul(it,yt),i=Math.imul(it,xt),i=i+Math.imul(rt,yt)|0,a=Math.imul(rt,xt);var si=(u+o|0)+((i&8191)<<13)|0;return u=(a+(i>>>13)|0)+(si>>>26)|0,si&=67108863,l[0]=Wt,l[1]=Ut,l[2]=zt,l[3]=Ht,l[4]=Vt,l[5]=Jt,l[6]=Qt,l[7]=Xt,l[8]=Yt,l[9]=$t,l[10]=Gt,l[11]=jt,l[12]=ti,l[13]=ii,l[14]=ri,l[15]=ei,l[16]=ni,l[17]=oi,l[18]=si,u!==0&&(l[19]=u,e.length++),e};Math.imul||(N=bt);function P(h,t,r){r.negative=t.negative^h.negative,r.length=h.length+t.length;for(var e=0,n=0,s=0;s<r.length-1;s++){var l=n;n=0;for(var u=e&67108863,o=Math.min(s,t.length-1),i=Math.max(0,s-h.length+1);i<=o;i++){var a=s-i,p=h.words[a]|0,c=t.words[i]|0,v=p*c,x=v&67108863;l=l+(v/67108864|0)|0,x=x+u|0,u=x&67108863,l=l+(x>>>26)|0,n+=l>>>26,l&=67108863}r.words[s]=u,e=l,l=n}return e!==0?r.words[s]=e:r.length--,r._strip()}function L(h,t,r){return P(h,t,r)}f.prototype.mulTo=function(t,r){var e,n=this.length+t.length;return this.length===10&&t.length===10?e=N(this,t,r):n<63?e=bt(this,t,r):n<1024?e=P(this,t,r):e=L(this,t,r),e};function q(h,t){this.x=h,this.y=t}q.prototype.makeRBT=function(t){for(var r=new Array(t),e=f.prototype._countBits(t)-1,n=0;n<t;n++)r[n]=this.revBin(n,e,t);return r},q.prototype.revBin=function(t,r,e){if(t===0||t===e-1)return t;for(var n=0,s=0;s<r;s++)n|=(t&1)<<r-s-1,t>>=1;return n},q.prototype.permute=function(t,r,e,n,s,l){for(var u=0;u<l;u++)n[u]=r[t[u]],s[u]=e[t[u]]},q.prototype.transform=function(t,r,e,n,s,l){this.permute(l,t,r,e,n,s);for(var u=1;u<s;u<<=1)for(var o=u<<1,i=Math.cos(2*Math.PI/o),a=Math.sin(2*Math.PI/o),p=0;p<s;p+=o)for(var c=i,v=a,x=0;x<u;x++){var O=e[p+x],I=n[p+x],Ot=e[p+x+u],F=n[p+x+u],Z=c*Ot-v*F;F=c*F+v*Ot,Ot=Z,e[p+x]=O+Ot,n[p+x]=I+F,e[p+x+u]=O-Ot,n[p+x+u]=I-F,x!==o&&(Z=i*c-a*v,v=i*v+a*c,c=Z)}},q.prototype.guessLen13b=function(t,r){var e=Math.max(r,t)|1,n=e&1,s=0;for(e=e/2|0;e;e=e>>>1)s++;return 1<<s+1+n},q.prototype.conjugate=function(t,r,e){if(!(e<=1))for(var n=0;n<e/2;n++){var s=t[n];t[n]=t[e-n-1],t[e-n-1]=s,s=r[n],r[n]=-r[e-n-1],r[e-n-1]=-s}},q.prototype.normalize13b=function(t,r){for(var e=0,n=0;n<r/2;n++){var s=Math.round(t[2*n+1]/r)*8192+Math.round(t[2*n]/r)+e;t[n]=s&67108863,s<67108864?e=0:e=s/67108864|0}return t},q.prototype.convert13b=function(t,r,e,n){for(var s=0,l=0;l<r;l++)s=s+(t[l]|0),e[2*l]=s&8191,s=s>>>13,e[2*l+1]=s&8191,s=s>>>13;for(l=2*r;l<n;++l)e[l]=0;d(s===0),d((s&-8192)===0)},q.prototype.stub=function(t){for(var r=new Array(t),e=0;e<t;e++)r[e]=0;return r},q.prototype.mulp=function(t,r,e){var n=2*this.guessLen13b(t.length,r.length),s=this.makeRBT(n),l=this.stub(n),u=new Array(n),o=new Array(n),i=new Array(n),a=new Array(n),p=new Array(n),c=new Array(n),v=e.words;v.length=n,this.convert13b(t.words,t.length,u,n),this.convert13b(r.words,r.length,a,n),this.transform(u,l,o,i,n,s),this.transform(a,l,p,c,n,s);for(var x=0;x<n;x++){var O=o[x]*p[x]-i[x]*c[x];i[x]=o[x]*c[x]+i[x]*p[x],o[x]=O}return this.conjugate(o,i,n),this.transform(o,i,v,l,n,s),this.conjugate(v,l,n),this.normalize13b(v,n),e.negative=t.negative^r.negative,e.length=t.length+r.length,e._strip()},f.prototype.mul=function(t){var r=new f(null);return r.words=new Array(this.length+t.length),this.mulTo(t,r)},f.prototype.mulf=function(t){var r=new f(null);return r.words=new Array(this.length+t.length),L(this,t,r)},f.prototype.imul=function(t){return this.clone().mulTo(t,this)},f.prototype.imuln=function(t){var r=t<0;r&&(t=-t),d(typeof t=="number"),d(t<67108864);for(var e=0,n=0;n<this.length;n++){var s=(this.words[n]|0)*t,l=(s&67108863)+(e&67108863);e>>=26,e+=s/67108864|0,e+=l>>>26,this.words[n]=l&67108863}return e!==0&&(this.words[n]=e,this.length++),this.length=t===0?1:this.length,r?this.ineg():this},f.prototype.muln=function(t){return this.clone().imuln(t)},f.prototype.sqr=function(){return this.mul(this)},f.prototype.isqr=function(){return this.imul(this.clone())},f.prototype.pow=function(t){var r=W(t);if(r.length===0)return new f(1);for(var e=this,n=0;n<r.length&&r[n]===0;n++,e=e.sqr());if(++n<r.length)for(var s=e.sqr();n<r.length;n++,s=s.sqr())r[n]!==0&&(e=e.mul(s));return e},f.prototype.iushln=function(t){d(typeof t=="number"&&t>=0);var r=t%26,e=(t-r)/26,n=67108863>>>26-r<<26-r,s;if(r!==0){var l=0;for(s=0;s<this.length;s++){var u=this.words[s]&n,o=(this.words[s]|0)-u<<r;this.words[s]=o|l,l=u>>>26-r}l&&(this.words[s]=l,this.length++)}if(e!==0){for(s=this.length-1;s>=0;s--)this.words[s+e]=this.words[s];for(s=0;s<e;s++)this.words[s]=0;this.length+=e}return this._strip()},f.prototype.ishln=function(t){return d(this.negative===0),this.iushln(t)},f.prototype.iushrn=function(t,r,e){d(typeof t=="number"&&t>=0);var n;r?n=(r-r%26)/26:n=0;var s=t%26,l=Math.min((t-s)/26,this.length),u=67108863^67108863>>>s<<s,o=e;if(n-=l,n=Math.max(0,n),o){for(var i=0;i<l;i++)o.words[i]=this.words[i];o.length=l}if(l!==0)if(this.length>l)for(this.length-=l,i=0;i<this.length;i++)this.words[i]=this.words[i+l];else this.words[0]=0,this.length=1;var a=0;for(i=this.length-1;i>=0&&(a!==0||i>=n);i--){var p=this.words[i]|0;this.words[i]=a<<26-s|p>>>s,a=p&u}return o&&a!==0&&(o.words[o.length++]=a),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},f.prototype.ishrn=function(t,r,e){return d(this.negative===0),this.iushrn(t,r,e)},f.prototype.shln=function(t){return this.clone().ishln(t)},f.prototype.ushln=function(t){return this.clone().iushln(t)},f.prototype.shrn=function(t){return this.clone().ishrn(t)},f.prototype.ushrn=function(t){return this.clone().iushrn(t)},f.prototype.testn=function(t){d(typeof t=="number"&&t>=0);var r=t%26,e=(t-r)/26,n=1<<r;if(this.length<=e)return!1;var s=this.words[e];return!!(s&n)},f.prototype.imaskn=function(t){d(typeof t=="number"&&t>=0);var r=t%26,e=(t-r)/26;if(d(this.negative===0,"imaskn works only with positive numbers"),this.length<=e)return this;if(r!==0&&e++,this.length=Math.min(e,this.length),r!==0){var n=67108863^67108863>>>r<<r;this.words[this.length-1]&=n}return this._strip()},f.prototype.maskn=function(t){return this.clone().imaskn(t)},f.prototype.iaddn=function(t){return d(typeof t=="number"),d(t<67108864),t<0?this.isubn(-t):this.negative!==0?this.length===1&&(this.words[0]|0)<=t?(this.words[0]=t-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},f.prototype._iaddn=function(t){this.words[0]+=t;for(var r=0;r<this.length&&this.words[r]>=67108864;r++)this.words[r]-=67108864,r===this.length-1?this.words[r+1]=1:this.words[r+1]++;return this.length=Math.max(this.length,r+1),this},f.prototype.isubn=function(t){if(d(typeof t=="number"),d(t<67108864),t<0)return this.iaddn(-t);if(this.negative!==0)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var r=0;r<this.length&&this.words[r]<0;r++)this.words[r]+=67108864,this.words[r+1]-=1;return this._strip()},f.prototype.addn=function(t){return this.clone().iaddn(t)},f.prototype.subn=function(t){return this.clone().isubn(t)},f.prototype.iabs=function(){return this.negative=0,this},f.prototype.abs=function(){return this.clone().iabs()},f.prototype._ishlnsubmul=function(t,r,e){var n=t.length+e,s;this._expand(n);var l,u=0;for(s=0;s<t.length;s++){l=(this.words[s+e]|0)+u;var o=(t.words[s]|0)*r;l-=o&67108863,u=(l>>26)-(o/67108864|0),this.words[s+e]=l&67108863}for(;s<this.length-e;s++)l=(this.words[s+e]|0)+u,u=l>>26,this.words[s+e]=l&67108863;if(u===0)return this._strip();for(d(u===-1),u=0,s=0;s<this.length;s++)l=-(this.words[s]|0)+u,u=l>>26,this.words[s]=l&67108863;return this.negative=1,this._strip()},f.prototype._wordDiv=function(t,r){var e=this.length-t.length,n=this.clone(),s=t,l=s.words[s.length-1]|0,u=this._countBits(l);e=26-u,e!==0&&(s=s.ushln(e),n.iushln(e),l=s.words[s.length-1]|0);var o=n.length-s.length,i;if(r!=="mod"){i=new f(null),i.length=o+1,i.words=new Array(i.length);for(var a=0;a<i.length;a++)i.words[a]=0}var p=n.clone()._ishlnsubmul(s,1,o);p.negative===0&&(n=p,i&&(i.words[o]=1));for(var c=o-1;c>=0;c--){var v=(n.words[s.length+c]|0)*67108864+(n.words[s.length+c-1]|0);for(v=Math.min(v/l|0,67108863),n._ishlnsubmul(s,v,c);n.negative!==0;)v--,n.negative=0,n._ishlnsubmul(s,1,c),n.isZero()||(n.negative^=1);i&&(i.words[c]=v)}return i&&i._strip(),n._strip(),r!=="div"&&e!==0&&n.iushrn(e),{div:i||null,mod:n}},f.prototype.divmod=function(t,r,e){if(d(!t.isZero()),this.isZero())return{div:new f(0),mod:new f(0)};var n,s,l;return this.negative!==0&&t.negative===0?(l=this.neg().divmod(t,r),r!=="mod"&&(n=l.div.neg()),r!=="div"&&(s=l.mod.neg(),e&&s.negative!==0&&s.iadd(t)),{div:n,mod:s}):this.negative===0&&t.negative!==0?(l=this.divmod(t.neg(),r),r!=="mod"&&(n=l.div.neg()),{div:n,mod:l.mod}):(this.negative&t.negative)!==0?(l=this.neg().divmod(t.neg(),r),r!=="div"&&(s=l.mod.neg(),e&&s.negative!==0&&s.isub(t)),{div:l.div,mod:s}):t.length>this.length||this.cmp(t)<0?{div:new f(0),mod:this}:t.length===1?r==="div"?{div:this.divn(t.words[0]),mod:null}:r==="mod"?{div:null,mod:new f(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new f(this.modrn(t.words[0]))}:this._wordDiv(t,r)},f.prototype.div=function(t){return this.divmod(t,"div",!1).div},f.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},f.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},f.prototype.divRound=function(t){var r=this.divmod(t);if(r.mod.isZero())return r.div;var e=r.div.negative!==0?r.mod.isub(t):r.mod,n=t.ushrn(1),s=t.andln(1),l=e.cmp(n);return l<0||s===1&&l===0?r.div:r.div.negative!==0?r.div.isubn(1):r.div.iaddn(1)},f.prototype.modrn=function(t){var r=t<0;r&&(t=-t),d(t<=67108863);for(var e=(1<<26)%t,n=0,s=this.length-1;s>=0;s--)n=(e*n+(this.words[s]|0))%t;return r?-n:n},f.prototype.modn=function(t){return this.modrn(t)},f.prototype.idivn=function(t){var r=t<0;r&&(t=-t),d(t<=67108863);for(var e=0,n=this.length-1;n>=0;n--){var s=(this.words[n]|0)+e*67108864;this.words[n]=s/t|0,e=s%t}return this._strip(),r?this.ineg():this},f.prototype.divn=function(t){return this.clone().idivn(t)},f.prototype.egcd=function(t){d(t.negative===0),d(!t.isZero());var r=this,e=t.clone();r.negative!==0?r=r.umod(t):r=r.clone();for(var n=new f(1),s=new f(0),l=new f(0),u=new f(1),o=0;r.isEven()&&e.isEven();)r.iushrn(1),e.iushrn(1),++o;for(var i=e.clone(),a=r.clone();!r.isZero();){for(var p=0,c=1;(r.words[0]&c)===0&&p<26;++p,c<<=1);if(p>0)for(r.iushrn(p);p-- >0;)(n.isOdd()||s.isOdd())&&(n.iadd(i),s.isub(a)),n.iushrn(1),s.iushrn(1);for(var v=0,x=1;(e.words[0]&x)===0&&v<26;++v,x<<=1);if(v>0)for(e.iushrn(v);v-- >0;)(l.isOdd()||u.isOdd())&&(l.iadd(i),u.isub(a)),l.iushrn(1),u.iushrn(1);r.cmp(e)>=0?(r.isub(e),n.isub(l),s.isub(u)):(e.isub(r),l.isub(n),u.isub(s))}return{a:l,b:u,gcd:e.iushln(o)}},f.prototype._invmp=function(t){d(t.negative===0),d(!t.isZero());var r=this,e=t.clone();r.negative!==0?r=r.umod(t):r=r.clone();for(var n=new f(1),s=new f(0),l=e.clone();r.cmpn(1)>0&&e.cmpn(1)>0;){for(var u=0,o=1;(r.words[0]&o)===0&&u<26;++u,o<<=1);if(u>0)for(r.iushrn(u);u-- >0;)n.isOdd()&&n.iadd(l),n.iushrn(1);for(var i=0,a=1;(e.words[0]&a)===0&&i<26;++i,a<<=1);if(i>0)for(e.iushrn(i);i-- >0;)s.isOdd()&&s.iadd(l),s.iushrn(1);r.cmp(e)>=0?(r.isub(e),n.isub(s)):(e.isub(r),s.isub(n))}var p;return r.cmpn(1)===0?p=n:p=s,p.cmpn(0)<0&&p.iadd(t),p},f.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var r=this.clone(),e=t.clone();r.negative=0,e.negative=0;for(var n=0;r.isEven()&&e.isEven();n++)r.iushrn(1),e.iushrn(1);do{for(;r.isEven();)r.iushrn(1);for(;e.isEven();)e.iushrn(1);var s=r.cmp(e);if(s<0){var l=r;r=e,e=l}else if(s===0||e.cmpn(1)===0)break;r.isub(e)}while(!0);return e.iushln(n)},f.prototype.invm=function(t){return this.egcd(t).a.umod(t)},f.prototype.isEven=function(){return(this.words[0]&1)===0},f.prototype.isOdd=function(){return(this.words[0]&1)===1},f.prototype.andln=function(t){return this.words[0]&t},f.prototype.bincn=function(t){d(typeof t=="number");var r=t%26,e=(t-r)/26,n=1<<r;if(this.length<=e)return this._expand(e+1),this.words[e]|=n,this;for(var s=n,l=e;s!==0&&l<this.length;l++){var u=this.words[l]|0;u+=s,s=u>>>26,u&=67108863,this.words[l]=u}return s!==0&&(this.words[l]=s,this.length++),this},f.prototype.isZero=function(){return this.length===1&&this.words[0]===0},f.prototype.cmpn=function(t){var r=t<0;if(this.negative!==0&&!r)return-1;if(this.negative===0&&r)return 1;this._strip();var e;if(this.length>1)e=1;else{r&&(t=-t),d(t<=67108863,"Number is too big");var n=this.words[0]|0;e=n===t?0:n<t?-1:1}return this.negative!==0?-e|0:e},f.prototype.cmp=function(t){if(this.negative!==0&&t.negative===0)return-1;if(this.negative===0&&t.negative!==0)return 1;var r=this.ucmp(t);return this.negative!==0?-r|0:r},f.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var r=0,e=this.length-1;e>=0;e--){var n=this.words[e]|0,s=t.words[e]|0;if(n!==s){n<s?r=-1:n>s&&(r=1);break}}return r},f.prototype.gtn=function(t){return this.cmpn(t)===1},f.prototype.gt=function(t){return this.cmp(t)===1},f.prototype.gten=function(t){return this.cmpn(t)>=0},f.prototype.gte=function(t){return this.cmp(t)>=0},f.prototype.ltn=function(t){return this.cmpn(t)===-1},f.prototype.lt=function(t){return this.cmp(t)===-1},f.prototype.lten=function(t){return this.cmpn(t)<=0},f.prototype.lte=function(t){return this.cmp(t)<=0},f.prototype.eqn=function(t){return this.cmpn(t)===0},f.prototype.eq=function(t){return this.cmp(t)===0},f.red=function(t){return new C(t)},f.prototype.toRed=function(t){return d(!this.red,"Already a number in reduction context"),d(this.negative===0,"red works only with positives"),t.convertTo(this)._forceRed(t)},f.prototype.fromRed=function(){return d(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},f.prototype._forceRed=function(t){return this.red=t,this},f.prototype.forceRed=function(t){return d(!this.red,"Already a number in reduction context"),this._forceRed(t)},f.prototype.redAdd=function(t){return d(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},f.prototype.redIAdd=function(t){return d(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},f.prototype.redSub=function(t){return d(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},f.prototype.redISub=function(t){return d(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},f.prototype.redShl=function(t){return d(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},f.prototype.redMul=function(t){return d(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},f.prototype.redIMul=function(t){return d(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},f.prototype.redSqr=function(){return d(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},f.prototype.redISqr=function(){return d(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},f.prototype.redSqrt=function(){return d(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},f.prototype.redInvm=function(){return d(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},f.prototype.redNeg=function(){return d(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},f.prototype.redPow=function(t){return d(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var T={k256:null,p224:null,p192:null,p25519:null};function R(h,t){this.name=h,this.p=new f(t,16),this.n=this.p.bitLength(),this.k=new f(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}R.prototype._tmp=function(){var t=new f(null);return t.words=new Array(Math.ceil(this.n/13)),t},R.prototype.ireduce=function(t){var r=t,e;do this.split(r,this.tmp),r=this.imulK(r),r=r.iadd(this.tmp),e=r.bitLength();while(e>this.n);var n=e<this.n?-1:r.ucmp(this.p);return n===0?(r.words[0]=0,r.length=1):n>0?r.isub(this.p):r.strip!==void 0?r.strip():r._strip(),r},R.prototype.split=function(t,r){t.iushrn(this.n,0,r)},R.prototype.imulK=function(t){return t.imul(this.k)};function Dt(){R.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}g(Dt,R),Dt.prototype.split=function(t,r){for(var e=4194303,n=Math.min(t.length,9),s=0;s<n;s++)r.words[s]=t.words[s];if(r.length=n,t.length<=9){t.words[0]=0,t.length=1;return}var l=t.words[9];for(r.words[r.length++]=l&e,s=10;s<t.length;s++){var u=t.words[s]|0;t.words[s-10]=(u&e)<<4|l>>>22,l=u}l>>>=22,t.words[s-10]=l,l===0&&t.length>10?t.length-=10:t.length-=9},Dt.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var r=0,e=0;e<t.length;e++){var n=t.words[e]|0;r+=n*977,t.words[e]=r&67108863,r=n*64+(r/67108864|0)}return t.words[t.length-1]===0&&(t.length--,t.words[t.length-1]===0&&t.length--),t};function St(){R.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}g(St,R);function Rt(){R.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}g(Rt,R);function qt(){R.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}g(qt,R),qt.prototype.imulK=function(t){for(var r=0,e=0;e<t.length;e++){var n=(t.words[e]|0)*19+r,s=n&67108863;n>>>=26,t.words[e]=s,r=n}return r!==0&&(t.words[t.length++]=r),t},f._prime=function(t){if(T[t])return T[t];var r;if(t==="k256")r=new Dt;else if(t==="p224")r=new St;else if(t==="p192")r=new Rt;else if(t==="p25519")r=new qt;else throw new Error("Unknown prime "+t);return T[t]=r,r};function C(h){if(typeof h=="string"){var t=f._prime(h);this.m=t.p,this.prime=t}else d(h.gtn(1),"modulus must be greater than 1"),this.m=h,this.prime=null}C.prototype._verify1=function(t){d(t.negative===0,"red works only with positives"),d(t.red,"red works only with red numbers")},C.prototype._verify2=function(t,r){d((t.negative|r.negative)===0,"red works only with positives"),d(t.red&&t.red===r.red,"red works only with red numbers")},C.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(b(t,t.umod(this.m)._forceRed(this)),t)},C.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},C.prototype.add=function(t,r){this._verify2(t,r);var e=t.add(r);return e.cmp(this.m)>=0&&e.isub(this.m),e._forceRed(this)},C.prototype.iadd=function(t,r){this._verify2(t,r);var e=t.iadd(r);return e.cmp(this.m)>=0&&e.isub(this.m),e},C.prototype.sub=function(t,r){this._verify2(t,r);var e=t.sub(r);return e.cmpn(0)<0&&e.iadd(this.m),e._forceRed(this)},C.prototype.isub=function(t,r){this._verify2(t,r);var e=t.isub(r);return e.cmpn(0)<0&&e.iadd(this.m),e},C.prototype.shl=function(t,r){return this._verify1(t),this.imod(t.ushln(r))},C.prototype.imul=function(t,r){return this._verify2(t,r),this.imod(t.imul(r))},C.prototype.mul=function(t,r){return this._verify2(t,r),this.imod(t.mul(r))},C.prototype.isqr=function(t){return this.imul(t,t.clone())},C.prototype.sqr=function(t){return this.mul(t,t)},C.prototype.sqrt=function(t){if(t.isZero())return t.clone();var r=this.m.andln(3);if(d(r%2===1),r===3){var e=this.m.add(new f(1)).iushrn(2);return this.pow(t,e)}for(var n=this.m.subn(1),s=0;!n.isZero()&&n.andln(1)===0;)s++,n.iushrn(1);d(!n.isZero());var l=new f(1).toRed(this),u=l.redNeg(),o=this.m.subn(1).iushrn(1),i=this.m.bitLength();for(i=new f(2*i*i).toRed(this);this.pow(i,o).cmp(u)!==0;)i.redIAdd(u);for(var a=this.pow(i,n),p=this.pow(t,n.addn(1).iushrn(1)),c=this.pow(t,n),v=s;c.cmp(l)!==0;){for(var x=c,O=0;x.cmp(l)!==0;O++)x=x.redSqr();d(O<v);var I=this.pow(a,new f(1).iushln(v-O-1));p=p.redMul(I),a=I.redSqr(),c=c.redMul(a),v=O}return p},C.prototype.invm=function(t){var r=t._invmp(this.m);return r.negative!==0?(r.negative=0,this.imod(r).redNeg()):this.imod(r)},C.prototype.pow=function(t,r){if(r.isZero())return new f(1).toRed(this);if(r.cmpn(1)===0)return t.clone();var e=4,n=new Array(1<<e);n[0]=new f(1).toRed(this),n[1]=t;for(var s=2;s<n.length;s++)n[s]=this.mul(n[s-1],t);var l=n[0],u=0,o=0,i=r.bitLength()%26;for(i===0&&(i=26),s=r.length-1;s>=0;s--){for(var a=r.words[s],p=i-1;p>=0;p--){var c=a>>p&1;if(l!==n[0]&&(l=this.sqr(l)),c===0&&u===0){o=0;continue}u<<=1,u|=c,o++,!(o!==e&&(s!==0||p!==0))&&(l=this.mul(l,n[u]),o=0,u=0)}i=26}return l},C.prototype.convertTo=function(t){var r=t.umod(this.m);return r===t?r.clone():r},C.prototype.convertFrom=function(t){var r=t.clone();return r.red=null,r},f.mont=function(t){return new Bt(t)};function Bt(h){C.call(this,h),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new f(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}g(Bt,C),Bt.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},Bt.prototype.convertFrom=function(t){var r=this.imod(t.mul(this.rinv));return r.red=null,r},Bt.prototype.imul=function(t,r){if(t.isZero()||r.isZero())return t.words[0]=0,t.length=1,t;var e=t.imul(r),n=e.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),s=e.isub(n).iushrn(this.shift),l=s;return s.cmp(this.m)>=0?l=s.isub(this.m):s.cmpn(0)<0&&(l=s.iadd(this.m)),l._forceRed(this)},Bt.prototype.mul=function(t,r){if(t.isZero()||r.isZero())return new f(0)._forceRed(this);var e=t.mul(r),n=e.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),s=e.isub(n).iushrn(this.shift),l=s;return s.cmp(this.m)>=0?l=s.isub(this.m):s.cmpn(0)<0&&(l=s.iadd(this.m)),l._forceRed(this)},Bt.prototype.invm=function(t){var r=this.imod(t._invmp(this.m).mul(this.r2));return r._forceRed(this)}})(typeof fi>"u"||fi,Ii)});var Gi={};Qi(Gi,{CetusDlmmZapSDK:()=>Tt,ZapError:()=>Lt,ZapErrorCode:()=>ui,ZapModule:()=>Pt,calcExactSwapAmount:()=>pi,calculateLiquidityAmountEnough:()=>mi,calculateLiquidityAmountSide:()=>Yi,default:()=>$i,defaultSwapSlippage:()=>Zt,handleError:()=>di,handleMessageError:()=>Ct,zapMainnet:()=>ai,zapTestnet:()=>hi});module.exports=Xi(Gi);var kt=require("@cetusprotocol/aggregator-sdk"),vi=require("@mysten/sui/client"),gi=require("@mysten/sui/utils"),Zi=require("@cetusprotocol/dlmm-sdk"),Ni=require("@cetusprotocol/common-sdk");var Ft=require("@cetusprotocol/common-sdk"),ai={env:"mainnet",full_rpc_url:Ft.FullRpcUrlMainnet,graph_rpc_url:Ft.GraphRpcUrlMainnet,aggregator_url:"https://api-sui.cetus.zone/router_v3",providers:[]};var Kt=require("@cetusprotocol/common-sdk"),hi={env:"testnet",full_rpc_url:Kt.FullRpcUrlTestnet,graph_rpc_url:Kt.GraphRpcUrlTestnet,aggregator_url:"https://api-sui.devcetus.com/router_v3",providers:["CETUS","DEEPBOOK","KRIYA","KRIYAV3","FLOWX","FLOWXV3","AFTERMATH","TURBOS","HAEDAL","VOLO","AFSUI"]};var ci=require("@mysten/sui/transactions"),Ki=Ti(li()),M=require("@cetusprotocol/common-sdk");var Fi=require("@cetusprotocol/common-sdk"),ui=(_=>(_.UnsupportedDepositMode="UnsupportedDepositMode",_.PositionIdUndefined="PositionIdUndefined",_.ParameterError="ParameterError",_.ReachMaxIterations="ReachMaxIterations",_.BestLiquidityIsZero="BestLiquidityIsZero",_.SwapAmountError="SwapAmountError",_.AggregatorError="AggregatorError",_))(ui||{}),Lt=class extends Fi.BaseError{constructor(m,d,g){super(m,d||"UnknownError",g)}static isZapErrorCode(m,d){return this.isErrorCode(m,d)}},di=(S,m,d)=>{throw new Lt(m.message,S,d)},Ct=(S,m,d)=>{throw new Lt(m,S,d)};var Zt=.005;var Et=Ti(li()),At=require("@cetusprotocol/common-sdk");function mi(S,m,d,g,f,A,w){let _=w?new Et.default(S):new Et.default(m),y=At.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(g,f,_,w,!0,A,new Et.default(d)),b=w?_.toString():y.coin_amount_a.toString(),D=w?y.coin_amount_b.toString():_.toString(),B=(0,At.d)(S).sub(b),K=(0,At.d)(m).sub(D);return{is_enough_amount:w?K.gte(0):B.gte(0),use_amount_a:b,use_amount_b:D,liquidity:y.liquidity_amount,amount_limit_a:y.coin_amount_limit_a,amount_limit_b:y.coin_amount_limit_b,remain_amount:w?K:B}}function Yi(S,m,d,g,f,A,w){let _=At.TickMath.sqrtPriceX64ToTickIndex(new Et.default(d)),y=w;_<g?y=!0:_>f&&(y=!1);let b=mi(S,m,d,g,f,A,y);return b.is_enough_amount||(y=!y,b=mi(S,m,d,g,f,A,y)),{fix_liquidity_amount_a:y,...b}}function pi(S,m,d,g){let f=(0,At.d)(S),A=(0,At.d)(d),w=(0,At.d)(g),_=f,y=m?f:(0,At.d)(0),b=m?(0,At.d)(0):f,D=w,B=(0,At.d)(w).mul(.999),K=(0,At.d)(0),k=_,E=null;function W(P){if(m){let L=y.minus(P),q=b.plus(P.mul(A));return{A:L,B:q,R:q.div(L)}}else{let L=y.plus(P.mul(A)),q=b.minus(P);return{A:L,B:q,R:L.div(q)}}}for(let P=0;P<120;P++){let L=K.plus(k).div(2),{A:q,B:T,R}=W(L);if(q.lte(0)||T.lte(0)){k=L;continue}if(R.gt(D))k=L;else if(R.lt(B))K=L;else{if(E=L,(0,At.d)(B).eq(0))break;k=L}}if(!E)return{swap_amount:"0",final_amount_a:y.toFixed(0),final_amount_b:b.toFixed(0)};let{A:bt,B:N}=W(E);return{swap_amount:E.toFixed(0),final_amount_a:bt.toFixed(0),final_amount_b:N.toFixed(0)}}var Nt=require("@cetusprotocol/dlmm-sdk"),Pt=class{constructor(m){this._sdk=m}get sdk(){return this._sdk}async calculateBalanceSwapAmountWithoutActiveId(m,d){let{fix_amount_a:g,coin_amount:f}=d,{bin_step:A,pool_id:w,active_id:_,lower_bin_id:y,upper_bin_id:b,active_bin_of_pool:D,strategy_type:B}=m,K=await this._sdk.DlmmSDK.Pool.getPool(w,!1),k,E=g,W=f;return _>b?(E=!1,g?(k=await this.findRouters(K.coin_type_a,K.coin_type_b,f),W=(0,M.d)(k.swap_out_amount).mul(1-.001).toFixed(0)):W=f):_<y&&(E=!0,g?W=f:(k=await this.findRouters(K.coin_type_b,K.coin_type_a,f),W=(0,M.d)(k.swap_out_amount).mul(1-.001).toFixed(0))),{liquidity_info:await this._sdk.DlmmSDK.Position.calculateAddLiquidityInfo({pool_id:w,coin_amount:W,fix_amount_a:E,active_id:_,bin_step:A,lower_bin_id:y,upper_bin_id:b,active_bin_of_pool:D,strategy_type:B}),swap_result:k}}async calculateBalanceSwapAmount(m,d){let{fix_amount_a:g,coin_amount:f}=d,{bin_step:A,pool_id:w,active_id:_,lower_bin_id:y,upper_bin_id:b,active_bin_of_pool:D,strategy_type:B}=m;if(_>b||_<y)return this.calculateBalanceSwapAmountWithoutActiveId(m,d);let K=await this._sdk.DlmmSDK.Position.calculateAddLiquidityInfo({pool_id:w,coin_amount:f,fix_amount_a:g,active_id:_,bin_step:A,lower_bin_id:y,upper_bin_id:b,active_bin_of_pool:D,strategy_type:B}),{amount_a:k,amount_b:E}=K,W=g?(0,M.d)(E).div(k):(0,M.d)(k).div(E),bt=g?Nt.BinUtils.getPricePerLamportFromBinId(_,A):(0,M.d)(1).div(Nt.BinUtils.getPricePerLamportFromBinId(_,A)).toString(),N=await this._sdk.DlmmSDK.Pool.getPool(w,!1);try{let t=await this.findRouters(g?N.coin_type_a:N.coin_type_b,g?N.coin_type_b:N.coin_type_a,f);t&&(bt=(0,M.d)(t.swap_out_amount).div(t.swap_in_amount).toString())}catch{}let{swap_amount:P,final_amount_a:L,final_amount_b:q}=pi(f,g,bt,W.toString());console.log("\u{1F680} ~ ZapModule ~ swap_amount:",{swap_amount:P,final_amount_a:L,final_amount_b:q,target_rate:W,real_price:bt,coin_amount:f,fix_amount_a:g});let T=P||"0",R,Dt,St,Rt=0,qt=.02,C,Bt,h;do{let t=(0,M.d)(f).sub(T).toFixed(0);St=await this.findRouters(g?N.coin_type_a:N.coin_type_b,g?N.coin_type_b:N.coin_type_a,T);let r=(0,M.d)(St.swap_out_amount).toFixed(0),e=await this._sdk.DlmmSDK.Position.calculateAddLiquidityInfo({pool_id:w,coin_amount:t,fix_amount_a:g,active_id:_,bin_step:A,lower_bin_id:y,upper_bin_id:b,active_bin_of_pool:D,strategy_type:B}),{amount_a:n,amount_b:s}=e,l=g?s:n,u=(0,M.d)(r).sub(l).div(r);if(u.gt(0)&&(h===void 0||u.lt(h))&&(C=St,Bt=e,h=u),(0,M.d)(r).gt(l))if((0,M.d)(u).gt(qt))console.log("calculateBalanceSwapAmount -: ",{swap_amount_in:T,real_remain_rate:u.toString(),cached_real_remain_rate:h?.toString(),temp_swap_result:St,deposit_amount_other:l,count:Rt}),T=(0,M.d)(T).mul(1-.01).toFixed(0),Rt++;else{R=St,Dt=e;break}else T=(0,M.d)(T).mul(1+.01).toFixed(0),T=Math.min(Number((0,M.d)(f).mul(1-1e-4).toFixed(0)),Number(T)).toString(),console.log("calculateBalanceSwapAmount +: ",{swap_amount_in:T,real_remain_rate:u.toString(),cached_real_remain_rate:h?.toString(),temp_swap_result:St,deposit_amount_other:l,count:Rt}),Rt++;if(Rt>5)break}while(!R&&(0,M.d)(T).gt(0));if(R===void 0&&C&&(R=C,Dt=Bt),R===void 0&&St){let{swap_out_amount:t}=St,r=await this._sdk.DlmmSDK.Position.calculateAddLiquidityInfo({pool_id:w,coin_amount:(0,M.d)(t).sub(1-.001).toFixed(0),fix_amount_a:!g,active_id:_,bin_step:A,lower_bin_id:y,upper_bin_id:b,active_bin_of_pool:D,strategy_type:B});R=St,Dt=r}return{swap_result:R,liquidity_info:Dt}}async preCalculateDepositAmount(m,d){let{fix_amount_a:g,coin_amount:f}=d;console.log("\u{1F680} ~ ZapModule ~ preCalculateDepositAmount ~ options:",{options:m,mode_options:d});let{liquidity_info:A,swap_result:w}=await this.calculateBalanceSwapAmount(m,d);return A===void 0?Ct("SwapAmountError","Best liquidity info is undefined",{[M.DETAILS_KEYS.METHOD_NAME]:"preCalculateDepositAmount"}):{bin_infos:A,swap_result:w,fix_amount_a:g,coin_amount:f}}async buildDepositPayload(m,d){let{swap_slippage:g=Zt,bin_step:f,pool_id:A,active_id:w,lower_bin_id:_,upper_bin_id:y,strategy_type:b,deposit_obj:D,slippage:B,pos_obj:K}=m,{fix_amount_a:k,coin_amount:E,swap_result:W,bin_infos:bt}=D;d=d||new ci.Transaction;let N=await this._sdk.DlmmSDK.Pool.getPool(A,!1),{coin_type_a:P,coin_type_b:L}=N,q,T;if(W){let R=k?P:L,{swap_in_amount:Dt,route_obj:St}=W,Rt=M.CoinAssist.buildCoinWithBalance(BigInt(Dt),R,d),qt={router:St,slippage:g,txb:d,inputCoin:Rt},C=await this._sdk.AggregatorClient.fixableRouterSwapV3(qt);k?(q=M.CoinAssist.buildCoinWithBalance(BigInt(bt.amount_a),P,d),T=C):(q=C,T=M.CoinAssist.buildCoinWithBalance(BigInt(bt.amount_b),L,d))}if(K){let R={pool_id:A,bin_infos:bt,coin_type_a:P,coin_type_b:L,active_id:w,strategy_type:b,max_price_slippage:B,bin_step:f,use_bin_infos:!1,position_id:K.pos_id,collect_fee:K.collect_fee,reward_coins:K.collect_rewarder_types,coin_object_id_a:q,coin_object_id_b:T};this._sdk.DlmmSDK.Position.addLiquidityPayload(R,d)}else{let R={pool_id:A,bin_infos:bt,coin_type_a:P,coin_type_b:L,lower_bin_id:_,upper_bin_id:y,active_id:w,strategy_type:b,use_bin_infos:!1,max_price_slippage:B,bin_step:f,coin_object_id_a:q,coin_object_id_b:T};this._sdk.DlmmSDK.Position.addLiquidityPayload(R,d)}return d}async findRouters(m,d,g){let{providers:f}=this._sdk.sdkOptions,A=this._sdk.AggregatorClient;if((0,M.d)(g).lt(1))return Ct("SwapAmountError","Swap amount is less than the minimum precision",{[M.DETAILS_KEYS.METHOD_NAME]:"findRouters"});try{let w={from:m,target:d,amount:new Ki.default(g),byAmountIn:!0,depth:3,providers:f},_=await A.findRouters(w);if(_?.error)return Ct("AggregatorError",`Aggregator findRouters error: ${_?.error}`,{[M.DETAILS_KEYS.METHOD_NAME]:"findRouters",[M.DETAILS_KEYS.REQUEST_PARAMS]:w});if(!_?.paths||_?.paths?.length===0)return Ct("AggregatorError","Aggregator findRouters error: no router",{[M.DETAILS_KEYS.METHOD_NAME]:"findRouters",[M.DETAILS_KEYS.REQUEST_PARAMS]:w});let y=_.amountIn.toString(),b=_.amountOut.toString();return{swap_in_amount:y,swap_out_amount:b,route_obj:_}}catch(w){return console.log("\u{1F680} ~ ZapModule ~ error:",JSON.stringify(w,null,2)),di("AggregatorError",w,{[M.DETAILS_KEYS.METHOD_NAME]:"swapInPools"})}}calculateZapOutAvailableAmount(m){let{is_receive_coin_a:d,mode:g,active_id:f,bin_step:A,remove_bin_range:w}=m,_=Nt.BinUtils.getPricePerLamportFromBinId(f,A),y,b="0",D="0",B="0";w.forEach(E=>{E.bin_id===f&&(y=E),b=(0,M.d)(b).add(E.amount_a).toFixed(0),D=(0,M.d)(D).add(E.amount_b).toFixed(0)});let K=(0,M.d)(b).sub(y?.amount_a||"0").toFixed(0),k=(0,M.d)(D).sub(y?.amount_b||"0").toFixed(0);return g==="OnlyCoinA"?d?B=K:B=(0,M.d)(b).mul(_).toFixed(0):g==="OnlyCoinB"?(D=k,d?B=(0,M.d)(D).div(_).toFixed(0):B=D):g==="Both"&&(d?B=(0,M.d)(D).div(_).add(b).toFixed(0):B=(0,M.d)(b).mul(_).add(D).toFixed(0)),{available_amount:B,user_total_amount_a:b,user_total_amount_b:D,active_bin:y,is_receive_coin_a:d}}async preCalculateWithdrawAmount(m){let{is_receive_coin_a:d,remove_bin_range:g,coin_type_a:f,coin_type_b:A,mode:w,expected_receive_amount:_,active_id:y}=m,{available_amount:b,user_total_amount_a:D,user_total_amount_b:B,active_bin:K}=this.calculateZapOutAvailableAmount(m);if((0,M.d)(b).lt((0,M.d)(_)))return Ct("SwapAmountError",`Available amount is less than the expected receive amount: ${b} < ${_}`,{[M.DETAILS_KEYS.METHOD_NAME]:"preCalculateWithdrawAmount",[M.DETAILS_KEYS.REQUEST_PARAMS]:m});let k=(0,M.d)(_).div(b),E;if(w==="Both"){let P=(0,M.d)(D).gt(0),L=P?(0,M.d)(D).mul(k).toFixed(0):(0,M.d)(B).mul(k).toFixed(0);E=this._sdk.DlmmSDK.Position.calculateRemoveLiquidityInfo({bins:g,active_id:y,fix_amount_a:P,coin_amount:L})}else{let P=w==="OnlyCoinA"?(0,M.d)(D).mul(k).toFixed(0):(0,M.d)(B).mul(k).toFixed(0);E=this._sdk.DlmmSDK.Position.calculateRemoveLiquidityInfo({bins:g,active_id:y,is_only_a:w==="OnlyCoinA",coin_amount:P})}let{amount_a:W,amount_b:bt}=E,N;return d&&(0,M.d)(bt).gt(0)&&(N=await this.findRouters(A,f,bt)),!d&&(0,M.d)(W).gt(0)&&(N=await this.findRouters(f,A,W)),{remove_liquidity_info:E,swap_result:N,mode:w,is_receive_coin_a:d,expected_receive_amount:_,remove_percent:k.toString()}}async buildWithdrawPayload(m){let d=new ci.Transaction,{withdraw_obj:g,swap_slippage:f=Zt,bin_step:A,pool_id:w,active_id:_,collect_fee:y,reward_coins:b,coin_type_a:D,coin_type_b:B,position_id:K,slippage:k,remove_percent:E,is_close_position:W}=m,{remove_liquidity_info:bt,swap_result:N,is_receive_coin_a:P}=g,L={pool_id:w,bin_infos:bt,coin_type_a:D,coin_type_b:B,position_id:K,slippage:k,active_id:_,reward_coins:b,collect_fee:y,bin_step:A,remove_percent:Number(E)},{coin_a_obj:q,coin_b_obj:T}=W?this._sdk.DlmmSDK.Position.closePositionNoTransferPayload(L,d):this._sdk.DlmmSDK.Position.removeLiquidityNoTransferPayload(L,d);if(N){let{route_obj:R}=N,Dt={router:R,slippage:f,txb:d,inputCoin:P?T:q},St=await this._sdk.AggregatorClient.fixableRouterSwapV3(Dt);P?d.transferObjects([q,St],this._sdk.getSenderAddress()):d.transferObjects([T,St],this._sdk.getSenderAddress())}else d.transferObjects([q,T],this._sdk.getSenderAddress());return d}};var Tt=class S extends Ni.SdkWrapper{constructor(m,d){super(m),this._zapModule=new Pt(this),this._dlmmSDK=d||Zi.CetusDlmmSDK.createSDK({env:m.env,full_rpc_url:m.full_rpc_url}),this._aggregatorClient=new kt.AggregatorClient({signer:(0,gi.normalizeSuiAddress)("0x0"),client:m.sui_client||new vi.SuiClient({url:m.full_rpc_url}),env:m.env==="testnet"?kt.Env.Testnet:kt.Env.Mainnet,pythUrls:m.pyth_urls})}setSenderAddress(m){this._dlmmSDK.setSenderAddress(m)}getSenderAddress(m=!0){return this._dlmmSDK.getSenderAddress(m)}updateProviders(m){if(m.length===0)throw new Error("providers is empty");this._sdkOptions.providers=m}updateFullRpcUrl(m){super.updateFullRpcUrl(m),this._dlmmSDK.updateFullRpcUrl(m),this._aggregatorClient=new kt.AggregatorClient({signer:(0,gi.normalizeSuiAddress)("0x0"),client:new vi.SuiClient({url:m}),env:this._sdkOptions.env==="testnet"?kt.Env.Testnet:kt.Env.Mainnet,pythUrls:this._sdkOptions.pyth_urls})}get DlmmSDK(){return this._dlmmSDK}get AggregatorClient(){return this._aggregatorClient}get Zap(){return this._zapModule}static createSDK(m,d){let{env:g="mainnet",full_rpc_url:f}=m;return g==="mainnet"?S.createCustomSDK({...ai,...m},d):S.createCustomSDK({...hi,...m},d)}static createCustomSDK(m,d){return new S(m,d)}};var $i=Tt;0&&(module.exports={CetusDlmmZapSDK,ZapError,ZapErrorCode,ZapModule,calcExactSwapAmount,calculateLiquidityAmountEnough,calculateLiquidityAmountSide,defaultSwapSlippage,handleError,handleMessageError,zapMainnet,zapTestnet});
|
|
1
|
+
"use strict";var Wi=Object.create;var It=Object.defineProperty;var Ui=Object.getOwnPropertyDescriptor;var zi=Object.getOwnPropertyNames;var Hi=Object.getPrototypeOf,Vi=Object.prototype.hasOwnProperty;var Ji=(x,m)=>()=>(m||x((m={exports:{}}).exports,m),m.exports),Qi=(x,m)=>{for(var d in m)It(x,d,{get:m[d],enumerable:!0})},Ti=(x,m,d,_)=>{if(m&&typeof m=="object"||typeof m=="function")for(let f of zi(m))!Vi.call(x,f)&&f!==d&&It(x,f,{get:()=>m[f],enumerable:!(_=Ui(m,f))||_.enumerable});return x};var Pi=(x,m,d)=>(d=x!=null?Wi(Hi(x)):{},Ti(m||!x||!x.__esModule?It(d,"default",{value:x,enumerable:!0}):d,x)),Xi=x=>Ti(It({},"__esModule",{value:!0}),x);var li=Ji((Ii,fi)=>{"use strict";(function(x,m){"use strict";function d(h,t){if(!h)throw new Error(t||"Assertion failed")}function _(h,t){h.super_=t;var r=function(){};r.prototype=t.prototype,h.prototype=new r,h.prototype.constructor=h}function f(h,t,r){if(f.isBN(h))return h;this.negative=0,this.words=null,this.length=0,this.red=null,h!==null&&((t==="le"||t==="be")&&(r=t,t=10),this._init(h||0,t||10,r||"be"))}typeof x=="object"?x.exports=f:m.BN=f,f.BN=f,f.wordSize=26;var S;try{typeof window<"u"&&typeof window.Buffer<"u"?S=window.Buffer:S=require("buffer").Buffer}catch{}f.isBN=function(t){return t instanceof f?!0:t!==null&&typeof t=="object"&&t.constructor.wordSize===f.wordSize&&Array.isArray(t.words)},f.max=function(t,r){return t.cmp(r)>0?t:r},f.min=function(t,r){return t.cmp(r)<0?t:r},f.prototype._init=function(t,r,e){if(typeof t=="number")return this._initNumber(t,r,e);if(typeof t=="object")return this._initArray(t,r,e);r==="hex"&&(r=16),d(r===(r|0)&&r>=2&&r<=36),t=t.toString().replace(/\s+/g,"");var n=0;t[0]==="-"&&(n++,this.negative=1),n<t.length&&(r===16?this._parseHex(t,n,e):(this._parseBase(t,r,n),e==="le"&&this._initArray(this.toArray(),r,e)))},f.prototype._initNumber=function(t,r,e){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[t&67108863],this.length=1):t<4503599627370496?(this.words=[t&67108863,t/67108864&67108863],this.length=2):(d(t<9007199254740992),this.words=[t&67108863,t/67108864&67108863,1],this.length=3),e==="le"&&this._initArray(this.toArray(),r,e)},f.prototype._initArray=function(t,r,e){if(d(typeof t.length=="number"),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var s,l,u=0;if(e==="be")for(n=t.length-1,s=0;n>=0;n-=3)l=t[n]|t[n-1]<<8|t[n-2]<<16,this.words[s]|=l<<u&67108863,this.words[s+1]=l>>>26-u&67108863,u+=24,u>=26&&(u-=26,s++);else if(e==="le")for(n=0,s=0;n<t.length;n+=3)l=t[n]|t[n+1]<<8|t[n+2]<<16,this.words[s]|=l<<u&67108863,this.words[s+1]=l>>>26-u&67108863,u+=24,u>=26&&(u-=26,s++);return this._strip()};function w(h,t){var r=h.charCodeAt(t);if(r>=48&&r<=57)return r-48;if(r>=65&&r<=70)return r-55;if(r>=97&&r<=102)return r-87;d(!1,"Invalid character in "+h)}function M(h,t,r){var e=w(h,r);return r-1>=t&&(e|=w(h,r-1)<<4),e}f.prototype._parseHex=function(t,r,e){this.length=Math.ceil((t.length-r)/6),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var s=0,l=0,u;if(e==="be")for(n=t.length-1;n>=r;n-=2)u=M(t,r,n)<<s,this.words[l]|=u&67108863,s>=18?(s-=18,l+=1,this.words[l]|=u>>>26):s+=8;else{var o=t.length-r;for(n=o%2===0?r+1:r;n<t.length;n+=2)u=M(t,r,n)<<s,this.words[l]|=u&67108863,s>=18?(s-=18,l+=1,this.words[l]|=u>>>26):s+=8}this._strip()};function y(h,t,r,e){for(var n=0,s=0,l=Math.min(h.length,r),u=t;u<l;u++){var o=h.charCodeAt(u)-48;n*=e,o>=49?s=o-49+10:o>=17?s=o-17+10:s=o,d(o>=0&&s<e,"Invalid character"),n+=s}return n}f.prototype._parseBase=function(t,r,e){this.words=[0],this.length=1;for(var n=0,s=1;s<=67108863;s*=r)n++;n--,s=s/r|0;for(var l=t.length-e,u=l%n,o=Math.min(l,l-u)+e,i=0,a=e;a<o;a+=n)i=y(t,a,a+n,r),this.imuln(s),this.words[0]+i<67108864?this.words[0]+=i:this._iaddn(i);if(u!==0){var p=1;for(i=y(t,a,t.length,r),a=0;a<u;a++)p*=r;this.imuln(p),this.words[0]+i<67108864?this.words[0]+=i:this._iaddn(i)}this._strip()},f.prototype.copy=function(t){t.words=new Array(this.length);for(var r=0;r<this.length;r++)t.words[r]=this.words[r];t.length=this.length,t.negative=this.negative,t.red=this.red};function A(h,t){h.words=t.words,h.length=t.length,h.negative=t.negative,h.red=t.red}if(f.prototype._move=function(t){A(t,this)},f.prototype.clone=function(){var t=new f(null);return this.copy(t),t},f.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},f.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},f.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{f.prototype[Symbol.for("nodejs.util.inspect.custom")]=L}catch{f.prototype.inspect=L}else f.prototype.inspect=L;function L(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var P=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],q=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],D=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];f.prototype.toString=function(t,r){t=t||10,r=r|0||1;var e;if(t===16||t==="hex"){e="";for(var n=0,s=0,l=0;l<this.length;l++){var u=this.words[l],o=((u<<n|s)&16777215).toString(16);s=u>>>24-n&16777215,n+=2,n>=26&&(n-=26,l--),s!==0||l!==this.length-1?e=P[6-o.length]+o+e:e=o+e}for(s!==0&&(e=s.toString(16)+e);e.length%r!==0;)e="0"+e;return this.negative!==0&&(e="-"+e),e}if(t===(t|0)&&t>=2&&t<=36){var i=q[t],a=D[t];e="";var p=this.clone();for(p.negative=0;!p.isZero();){var v=p.modrn(a).toString(t);p=p.idivn(a),p.isZero()?e=v+e:e=P[i-v.length]+v+e}for(this.isZero()&&(e="0"+e);e.length%r!==0;)e="0"+e;return this.negative!==0&&(e="-"+e),e}d(!1,"Base should be between 2 and 36")},f.prototype.toNumber=function(){var t=this.words[0];return this.length===2?t+=this.words[1]*67108864:this.length===3&&this.words[2]===1?t+=4503599627370496+this.words[1]*67108864:this.length>2&&d(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-t:t},f.prototype.toJSON=function(){return this.toString(16,2)},S&&(f.prototype.toBuffer=function(t,r){return this.toArrayLike(S,t,r)}),f.prototype.toArray=function(t,r){return this.toArrayLike(Array,t,r)};var C=function(t,r){return t.allocUnsafe?t.allocUnsafe(r):new t(r)};f.prototype.toArrayLike=function(t,r,e){this._strip();var n=this.byteLength(),s=e||Math.max(1,n);d(n<=s,"byte array longer than desired length"),d(s>0,"Requested array length <= 0");var l=C(t,s),u=r==="le"?"LE":"BE";return this["_toArrayLike"+u](l,n),l},f.prototype._toArrayLikeLE=function(t,r){for(var e=0,n=0,s=0,l=0;s<this.length;s++){var u=this.words[s]<<l|n;t[e++]=u&255,e<t.length&&(t[e++]=u>>8&255),e<t.length&&(t[e++]=u>>16&255),l===6?(e<t.length&&(t[e++]=u>>24&255),n=0,l=0):(n=u>>>24,l+=2)}if(e<t.length)for(t[e++]=n;e<t.length;)t[e++]=0},f.prototype._toArrayLikeBE=function(t,r){for(var e=t.length-1,n=0,s=0,l=0;s<this.length;s++){var u=this.words[s]<<l|n;t[e--]=u&255,e>=0&&(t[e--]=u>>8&255),e>=0&&(t[e--]=u>>16&255),l===6?(e>=0&&(t[e--]=u>>24&255),n=0,l=0):(n=u>>>24,l+=2)}if(e>=0)for(t[e--]=n;e>=0;)t[e--]=0},Math.clz32?f.prototype._countBits=function(t){return 32-Math.clz32(t)}:f.prototype._countBits=function(t){var r=t,e=0;return r>=4096&&(e+=13,r>>>=13),r>=64&&(e+=7,r>>>=7),r>=8&&(e+=4,r>>>=4),r>=2&&(e+=2,r>>>=2),e+r},f.prototype._zeroBits=function(t){if(t===0)return 26;var r=t,e=0;return(r&8191)===0&&(e+=13,r>>>=13),(r&127)===0&&(e+=7,r>>>=7),(r&15)===0&&(e+=4,r>>>=4),(r&3)===0&&(e+=2,r>>>=2),(r&1)===0&&e++,e},f.prototype.bitLength=function(){var t=this.words[this.length-1],r=this._countBits(t);return(this.length-1)*26+r};function W(h){for(var t=new Array(h.bitLength()),r=0;r<t.length;r++){var e=r/26|0,n=r%26;t[r]=h.words[e]>>>n&1}return t}f.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,r=0;r<this.length;r++){var e=this._zeroBits(this.words[r]);if(t+=e,e!==26)break}return t},f.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},f.prototype.toTwos=function(t){return this.negative!==0?this.abs().inotn(t).iaddn(1):this.clone()},f.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},f.prototype.isNeg=function(){return this.negative!==0},f.prototype.neg=function(){return this.clone().ineg()},f.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},f.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var r=0;r<t.length;r++)this.words[r]=this.words[r]|t.words[r];return this._strip()},f.prototype.ior=function(t){return d((this.negative|t.negative)===0),this.iuor(t)},f.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},f.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},f.prototype.iuand=function(t){var r;this.length>t.length?r=t:r=this;for(var e=0;e<r.length;e++)this.words[e]=this.words[e]&t.words[e];return this.length=r.length,this._strip()},f.prototype.iand=function(t){return d((this.negative|t.negative)===0),this.iuand(t)},f.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},f.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},f.prototype.iuxor=function(t){var r,e;this.length>t.length?(r=this,e=t):(r=t,e=this);for(var n=0;n<e.length;n++)this.words[n]=r.words[n]^e.words[n];if(this!==r)for(;n<r.length;n++)this.words[n]=r.words[n];return this.length=r.length,this._strip()},f.prototype.ixor=function(t){return d((this.negative|t.negative)===0),this.iuxor(t)},f.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},f.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},f.prototype.inotn=function(t){d(typeof t=="number"&&t>=0);var r=Math.ceil(t/26)|0,e=t%26;this._expand(r),e>0&&r--;for(var n=0;n<r;n++)this.words[n]=~this.words[n]&67108863;return e>0&&(this.words[n]=~this.words[n]&67108863>>26-e),this._strip()},f.prototype.notn=function(t){return this.clone().inotn(t)},f.prototype.setn=function(t,r){d(typeof t=="number"&&t>=0);var e=t/26|0,n=t%26;return this._expand(e+1),r?this.words[e]=this.words[e]|1<<n:this.words[e]=this.words[e]&~(1<<n),this._strip()},f.prototype.iadd=function(t){var r;if(this.negative!==0&&t.negative===0)return this.negative=0,r=this.isub(t),this.negative^=1,this._normSign();if(this.negative===0&&t.negative!==0)return t.negative=0,r=this.isub(t),t.negative=1,r._normSign();var e,n;this.length>t.length?(e=this,n=t):(e=t,n=this);for(var s=0,l=0;l<n.length;l++)r=(e.words[l]|0)+(n.words[l]|0)+s,this.words[l]=r&67108863,s=r>>>26;for(;s!==0&&l<e.length;l++)r=(e.words[l]|0)+s,this.words[l]=r&67108863,s=r>>>26;if(this.length=e.length,s!==0)this.words[this.length]=s,this.length++;else if(e!==this)for(;l<e.length;l++)this.words[l]=e.words[l];return this},f.prototype.add=function(t){var r;return t.negative!==0&&this.negative===0?(t.negative=0,r=this.sub(t),t.negative^=1,r):t.negative===0&&this.negative!==0?(this.negative=0,r=t.sub(this),this.negative=1,r):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},f.prototype.isub=function(t){if(t.negative!==0){t.negative=0;var r=this.iadd(t);return t.negative=1,r._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var e=this.cmp(t);if(e===0)return this.negative=0,this.length=1,this.words[0]=0,this;var n,s;e>0?(n=this,s=t):(n=t,s=this);for(var l=0,u=0;u<s.length;u++)r=(n.words[u]|0)-(s.words[u]|0)+l,l=r>>26,this.words[u]=r&67108863;for(;l!==0&&u<n.length;u++)r=(n.words[u]|0)+l,l=r>>26,this.words[u]=r&67108863;if(l===0&&u<n.length&&n!==this)for(;u<n.length;u++)this.words[u]=n.words[u];return this.length=Math.max(this.length,u),n!==this&&(this.negative=1),this._strip()},f.prototype.sub=function(t){return this.clone().isub(t)};function U(h,t,r){r.negative=t.negative^h.negative;var e=h.length+t.length|0;r.length=e,e=e-1|0;var n=h.words[0]|0,s=t.words[0]|0,l=n*s,u=l&67108863,o=l/67108864|0;r.words[0]=u;for(var i=1;i<e;i++){for(var a=o>>>26,p=o&67108863,v=Math.min(i,t.length-1),g=Math.max(0,i-h.length+1);g<=v;g++){var b=i-g|0;n=h.words[b]|0,s=t.words[g]|0,l=n*s+p,a+=l/67108864|0,p=l&67108863}r.words[i]=p|0,o=a|0}return o!==0?r.words[i]=o|0:r.length--,r._strip()}var Z=function(t,r,e){var n=t.words,s=r.words,l=e.words,u=0,o,i,a,p=n[0]|0,v=p&8191,g=p>>>13,b=n[1]|0,k=b&8191,F=b>>>13,Ot=n[2]|0,K=Ot&8191,N=Ot>>>13,_i=n[3]|0,z=_i&8191,H=_i>>>13,Mi=n[4]|0,V=Mi&8191,J=Mi>>>13,wi=n[5]|0,Q=wi&8191,X=wi>>>13,yi=n[6]|0,Y=yi&8191,$=yi>>>13,bi=n[7]|0,G=bi&8191,j=bi>>>13,xi=n[8]|0,tt=xi&8191,it=xi>>>13,Si=n[9]|0,rt=Si&8191,et=Si>>>13,Ai=s[0]|0,nt=Ai&8191,ot=Ai>>>13,Di=s[1]|0,st=Di&8191,at=Di>>>13,Ri=s[2]|0,ht=Ri&8191,ft=Ri>>>13,Bi=s[3]|0,lt=Bi&8191,ut=Bi>>>13,Oi=s[4]|0,dt=Oi&8191,mt=Oi>>>13,ki=s[5]|0,pt=ki&8191,ct=ki>>>13,qi=s[6]|0,vt=qi&8191,gt=qi>>>13,Ci=s[7]|0,_t=Ci&8191,Mt=Ci>>>13,Ei=s[8]|0,wt=Ei&8191,yt=Ei>>>13,Li=s[9]|0,bt=Li&8191,xt=Li>>>13;e.negative=t.negative^r.negative,e.length=19,o=Math.imul(v,nt),i=Math.imul(v,ot),i=i+Math.imul(g,nt)|0,a=Math.imul(g,ot);var Wt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Wt>>>26)|0,Wt&=67108863,o=Math.imul(k,nt),i=Math.imul(k,ot),i=i+Math.imul(F,nt)|0,a=Math.imul(F,ot),o=o+Math.imul(v,st)|0,i=i+Math.imul(v,at)|0,i=i+Math.imul(g,st)|0,a=a+Math.imul(g,at)|0;var Ut=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Ut>>>26)|0,Ut&=67108863,o=Math.imul(K,nt),i=Math.imul(K,ot),i=i+Math.imul(N,nt)|0,a=Math.imul(N,ot),o=o+Math.imul(k,st)|0,i=i+Math.imul(k,at)|0,i=i+Math.imul(F,st)|0,a=a+Math.imul(F,at)|0,o=o+Math.imul(v,ht)|0,i=i+Math.imul(v,ft)|0,i=i+Math.imul(g,ht)|0,a=a+Math.imul(g,ft)|0;var zt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(zt>>>26)|0,zt&=67108863,o=Math.imul(z,nt),i=Math.imul(z,ot),i=i+Math.imul(H,nt)|0,a=Math.imul(H,ot),o=o+Math.imul(K,st)|0,i=i+Math.imul(K,at)|0,i=i+Math.imul(N,st)|0,a=a+Math.imul(N,at)|0,o=o+Math.imul(k,ht)|0,i=i+Math.imul(k,ft)|0,i=i+Math.imul(F,ht)|0,a=a+Math.imul(F,ft)|0,o=o+Math.imul(v,lt)|0,i=i+Math.imul(v,ut)|0,i=i+Math.imul(g,lt)|0,a=a+Math.imul(g,ut)|0;var Ht=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Ht>>>26)|0,Ht&=67108863,o=Math.imul(V,nt),i=Math.imul(V,ot),i=i+Math.imul(J,nt)|0,a=Math.imul(J,ot),o=o+Math.imul(z,st)|0,i=i+Math.imul(z,at)|0,i=i+Math.imul(H,st)|0,a=a+Math.imul(H,at)|0,o=o+Math.imul(K,ht)|0,i=i+Math.imul(K,ft)|0,i=i+Math.imul(N,ht)|0,a=a+Math.imul(N,ft)|0,o=o+Math.imul(k,lt)|0,i=i+Math.imul(k,ut)|0,i=i+Math.imul(F,lt)|0,a=a+Math.imul(F,ut)|0,o=o+Math.imul(v,dt)|0,i=i+Math.imul(v,mt)|0,i=i+Math.imul(g,dt)|0,a=a+Math.imul(g,mt)|0;var Vt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Vt>>>26)|0,Vt&=67108863,o=Math.imul(Q,nt),i=Math.imul(Q,ot),i=i+Math.imul(X,nt)|0,a=Math.imul(X,ot),o=o+Math.imul(V,st)|0,i=i+Math.imul(V,at)|0,i=i+Math.imul(J,st)|0,a=a+Math.imul(J,at)|0,o=o+Math.imul(z,ht)|0,i=i+Math.imul(z,ft)|0,i=i+Math.imul(H,ht)|0,a=a+Math.imul(H,ft)|0,o=o+Math.imul(K,lt)|0,i=i+Math.imul(K,ut)|0,i=i+Math.imul(N,lt)|0,a=a+Math.imul(N,ut)|0,o=o+Math.imul(k,dt)|0,i=i+Math.imul(k,mt)|0,i=i+Math.imul(F,dt)|0,a=a+Math.imul(F,mt)|0,o=o+Math.imul(v,pt)|0,i=i+Math.imul(v,ct)|0,i=i+Math.imul(g,pt)|0,a=a+Math.imul(g,ct)|0;var Jt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Jt>>>26)|0,Jt&=67108863,o=Math.imul(Y,nt),i=Math.imul(Y,ot),i=i+Math.imul($,nt)|0,a=Math.imul($,ot),o=o+Math.imul(Q,st)|0,i=i+Math.imul(Q,at)|0,i=i+Math.imul(X,st)|0,a=a+Math.imul(X,at)|0,o=o+Math.imul(V,ht)|0,i=i+Math.imul(V,ft)|0,i=i+Math.imul(J,ht)|0,a=a+Math.imul(J,ft)|0,o=o+Math.imul(z,lt)|0,i=i+Math.imul(z,ut)|0,i=i+Math.imul(H,lt)|0,a=a+Math.imul(H,ut)|0,o=o+Math.imul(K,dt)|0,i=i+Math.imul(K,mt)|0,i=i+Math.imul(N,dt)|0,a=a+Math.imul(N,mt)|0,o=o+Math.imul(k,pt)|0,i=i+Math.imul(k,ct)|0,i=i+Math.imul(F,pt)|0,a=a+Math.imul(F,ct)|0,o=o+Math.imul(v,vt)|0,i=i+Math.imul(v,gt)|0,i=i+Math.imul(g,vt)|0,a=a+Math.imul(g,gt)|0;var Qt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,o=Math.imul(G,nt),i=Math.imul(G,ot),i=i+Math.imul(j,nt)|0,a=Math.imul(j,ot),o=o+Math.imul(Y,st)|0,i=i+Math.imul(Y,at)|0,i=i+Math.imul($,st)|0,a=a+Math.imul($,at)|0,o=o+Math.imul(Q,ht)|0,i=i+Math.imul(Q,ft)|0,i=i+Math.imul(X,ht)|0,a=a+Math.imul(X,ft)|0,o=o+Math.imul(V,lt)|0,i=i+Math.imul(V,ut)|0,i=i+Math.imul(J,lt)|0,a=a+Math.imul(J,ut)|0,o=o+Math.imul(z,dt)|0,i=i+Math.imul(z,mt)|0,i=i+Math.imul(H,dt)|0,a=a+Math.imul(H,mt)|0,o=o+Math.imul(K,pt)|0,i=i+Math.imul(K,ct)|0,i=i+Math.imul(N,pt)|0,a=a+Math.imul(N,ct)|0,o=o+Math.imul(k,vt)|0,i=i+Math.imul(k,gt)|0,i=i+Math.imul(F,vt)|0,a=a+Math.imul(F,gt)|0,o=o+Math.imul(v,_t)|0,i=i+Math.imul(v,Mt)|0,i=i+Math.imul(g,_t)|0,a=a+Math.imul(g,Mt)|0;var Xt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Xt>>>26)|0,Xt&=67108863,o=Math.imul(tt,nt),i=Math.imul(tt,ot),i=i+Math.imul(it,nt)|0,a=Math.imul(it,ot),o=o+Math.imul(G,st)|0,i=i+Math.imul(G,at)|0,i=i+Math.imul(j,st)|0,a=a+Math.imul(j,at)|0,o=o+Math.imul(Y,ht)|0,i=i+Math.imul(Y,ft)|0,i=i+Math.imul($,ht)|0,a=a+Math.imul($,ft)|0,o=o+Math.imul(Q,lt)|0,i=i+Math.imul(Q,ut)|0,i=i+Math.imul(X,lt)|0,a=a+Math.imul(X,ut)|0,o=o+Math.imul(V,dt)|0,i=i+Math.imul(V,mt)|0,i=i+Math.imul(J,dt)|0,a=a+Math.imul(J,mt)|0,o=o+Math.imul(z,pt)|0,i=i+Math.imul(z,ct)|0,i=i+Math.imul(H,pt)|0,a=a+Math.imul(H,ct)|0,o=o+Math.imul(K,vt)|0,i=i+Math.imul(K,gt)|0,i=i+Math.imul(N,vt)|0,a=a+Math.imul(N,gt)|0,o=o+Math.imul(k,_t)|0,i=i+Math.imul(k,Mt)|0,i=i+Math.imul(F,_t)|0,a=a+Math.imul(F,Mt)|0,o=o+Math.imul(v,wt)|0,i=i+Math.imul(v,yt)|0,i=i+Math.imul(g,wt)|0,a=a+Math.imul(g,yt)|0;var Yt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Yt>>>26)|0,Yt&=67108863,o=Math.imul(rt,nt),i=Math.imul(rt,ot),i=i+Math.imul(et,nt)|0,a=Math.imul(et,ot),o=o+Math.imul(tt,st)|0,i=i+Math.imul(tt,at)|0,i=i+Math.imul(it,st)|0,a=a+Math.imul(it,at)|0,o=o+Math.imul(G,ht)|0,i=i+Math.imul(G,ft)|0,i=i+Math.imul(j,ht)|0,a=a+Math.imul(j,ft)|0,o=o+Math.imul(Y,lt)|0,i=i+Math.imul(Y,ut)|0,i=i+Math.imul($,lt)|0,a=a+Math.imul($,ut)|0,o=o+Math.imul(Q,dt)|0,i=i+Math.imul(Q,mt)|0,i=i+Math.imul(X,dt)|0,a=a+Math.imul(X,mt)|0,o=o+Math.imul(V,pt)|0,i=i+Math.imul(V,ct)|0,i=i+Math.imul(J,pt)|0,a=a+Math.imul(J,ct)|0,o=o+Math.imul(z,vt)|0,i=i+Math.imul(z,gt)|0,i=i+Math.imul(H,vt)|0,a=a+Math.imul(H,gt)|0,o=o+Math.imul(K,_t)|0,i=i+Math.imul(K,Mt)|0,i=i+Math.imul(N,_t)|0,a=a+Math.imul(N,Mt)|0,o=o+Math.imul(k,wt)|0,i=i+Math.imul(k,yt)|0,i=i+Math.imul(F,wt)|0,a=a+Math.imul(F,yt)|0,o=o+Math.imul(v,bt)|0,i=i+Math.imul(v,xt)|0,i=i+Math.imul(g,bt)|0,a=a+Math.imul(g,xt)|0;var $t=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+($t>>>26)|0,$t&=67108863,o=Math.imul(rt,st),i=Math.imul(rt,at),i=i+Math.imul(et,st)|0,a=Math.imul(et,at),o=o+Math.imul(tt,ht)|0,i=i+Math.imul(tt,ft)|0,i=i+Math.imul(it,ht)|0,a=a+Math.imul(it,ft)|0,o=o+Math.imul(G,lt)|0,i=i+Math.imul(G,ut)|0,i=i+Math.imul(j,lt)|0,a=a+Math.imul(j,ut)|0,o=o+Math.imul(Y,dt)|0,i=i+Math.imul(Y,mt)|0,i=i+Math.imul($,dt)|0,a=a+Math.imul($,mt)|0,o=o+Math.imul(Q,pt)|0,i=i+Math.imul(Q,ct)|0,i=i+Math.imul(X,pt)|0,a=a+Math.imul(X,ct)|0,o=o+Math.imul(V,vt)|0,i=i+Math.imul(V,gt)|0,i=i+Math.imul(J,vt)|0,a=a+Math.imul(J,gt)|0,o=o+Math.imul(z,_t)|0,i=i+Math.imul(z,Mt)|0,i=i+Math.imul(H,_t)|0,a=a+Math.imul(H,Mt)|0,o=o+Math.imul(K,wt)|0,i=i+Math.imul(K,yt)|0,i=i+Math.imul(N,wt)|0,a=a+Math.imul(N,yt)|0,o=o+Math.imul(k,bt)|0,i=i+Math.imul(k,xt)|0,i=i+Math.imul(F,bt)|0,a=a+Math.imul(F,xt)|0;var Gt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Gt>>>26)|0,Gt&=67108863,o=Math.imul(rt,ht),i=Math.imul(rt,ft),i=i+Math.imul(et,ht)|0,a=Math.imul(et,ft),o=o+Math.imul(tt,lt)|0,i=i+Math.imul(tt,ut)|0,i=i+Math.imul(it,lt)|0,a=a+Math.imul(it,ut)|0,o=o+Math.imul(G,dt)|0,i=i+Math.imul(G,mt)|0,i=i+Math.imul(j,dt)|0,a=a+Math.imul(j,mt)|0,o=o+Math.imul(Y,pt)|0,i=i+Math.imul(Y,ct)|0,i=i+Math.imul($,pt)|0,a=a+Math.imul($,ct)|0,o=o+Math.imul(Q,vt)|0,i=i+Math.imul(Q,gt)|0,i=i+Math.imul(X,vt)|0,a=a+Math.imul(X,gt)|0,o=o+Math.imul(V,_t)|0,i=i+Math.imul(V,Mt)|0,i=i+Math.imul(J,_t)|0,a=a+Math.imul(J,Mt)|0,o=o+Math.imul(z,wt)|0,i=i+Math.imul(z,yt)|0,i=i+Math.imul(H,wt)|0,a=a+Math.imul(H,yt)|0,o=o+Math.imul(K,bt)|0,i=i+Math.imul(K,xt)|0,i=i+Math.imul(N,bt)|0,a=a+Math.imul(N,xt)|0;var jt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(jt>>>26)|0,jt&=67108863,o=Math.imul(rt,lt),i=Math.imul(rt,ut),i=i+Math.imul(et,lt)|0,a=Math.imul(et,ut),o=o+Math.imul(tt,dt)|0,i=i+Math.imul(tt,mt)|0,i=i+Math.imul(it,dt)|0,a=a+Math.imul(it,mt)|0,o=o+Math.imul(G,pt)|0,i=i+Math.imul(G,ct)|0,i=i+Math.imul(j,pt)|0,a=a+Math.imul(j,ct)|0,o=o+Math.imul(Y,vt)|0,i=i+Math.imul(Y,gt)|0,i=i+Math.imul($,vt)|0,a=a+Math.imul($,gt)|0,o=o+Math.imul(Q,_t)|0,i=i+Math.imul(Q,Mt)|0,i=i+Math.imul(X,_t)|0,a=a+Math.imul(X,Mt)|0,o=o+Math.imul(V,wt)|0,i=i+Math.imul(V,yt)|0,i=i+Math.imul(J,wt)|0,a=a+Math.imul(J,yt)|0,o=o+Math.imul(z,bt)|0,i=i+Math.imul(z,xt)|0,i=i+Math.imul(H,bt)|0,a=a+Math.imul(H,xt)|0;var ti=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(ti>>>26)|0,ti&=67108863,o=Math.imul(rt,dt),i=Math.imul(rt,mt),i=i+Math.imul(et,dt)|0,a=Math.imul(et,mt),o=o+Math.imul(tt,pt)|0,i=i+Math.imul(tt,ct)|0,i=i+Math.imul(it,pt)|0,a=a+Math.imul(it,ct)|0,o=o+Math.imul(G,vt)|0,i=i+Math.imul(G,gt)|0,i=i+Math.imul(j,vt)|0,a=a+Math.imul(j,gt)|0,o=o+Math.imul(Y,_t)|0,i=i+Math.imul(Y,Mt)|0,i=i+Math.imul($,_t)|0,a=a+Math.imul($,Mt)|0,o=o+Math.imul(Q,wt)|0,i=i+Math.imul(Q,yt)|0,i=i+Math.imul(X,wt)|0,a=a+Math.imul(X,yt)|0,o=o+Math.imul(V,bt)|0,i=i+Math.imul(V,xt)|0,i=i+Math.imul(J,bt)|0,a=a+Math.imul(J,xt)|0;var ii=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(ii>>>26)|0,ii&=67108863,o=Math.imul(rt,pt),i=Math.imul(rt,ct),i=i+Math.imul(et,pt)|0,a=Math.imul(et,ct),o=o+Math.imul(tt,vt)|0,i=i+Math.imul(tt,gt)|0,i=i+Math.imul(it,vt)|0,a=a+Math.imul(it,gt)|0,o=o+Math.imul(G,_t)|0,i=i+Math.imul(G,Mt)|0,i=i+Math.imul(j,_t)|0,a=a+Math.imul(j,Mt)|0,o=o+Math.imul(Y,wt)|0,i=i+Math.imul(Y,yt)|0,i=i+Math.imul($,wt)|0,a=a+Math.imul($,yt)|0,o=o+Math.imul(Q,bt)|0,i=i+Math.imul(Q,xt)|0,i=i+Math.imul(X,bt)|0,a=a+Math.imul(X,xt)|0;var ri=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(ri>>>26)|0,ri&=67108863,o=Math.imul(rt,vt),i=Math.imul(rt,gt),i=i+Math.imul(et,vt)|0,a=Math.imul(et,gt),o=o+Math.imul(tt,_t)|0,i=i+Math.imul(tt,Mt)|0,i=i+Math.imul(it,_t)|0,a=a+Math.imul(it,Mt)|0,o=o+Math.imul(G,wt)|0,i=i+Math.imul(G,yt)|0,i=i+Math.imul(j,wt)|0,a=a+Math.imul(j,yt)|0,o=o+Math.imul(Y,bt)|0,i=i+Math.imul(Y,xt)|0,i=i+Math.imul($,bt)|0,a=a+Math.imul($,xt)|0;var ei=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(ei>>>26)|0,ei&=67108863,o=Math.imul(rt,_t),i=Math.imul(rt,Mt),i=i+Math.imul(et,_t)|0,a=Math.imul(et,Mt),o=o+Math.imul(tt,wt)|0,i=i+Math.imul(tt,yt)|0,i=i+Math.imul(it,wt)|0,a=a+Math.imul(it,yt)|0,o=o+Math.imul(G,bt)|0,i=i+Math.imul(G,xt)|0,i=i+Math.imul(j,bt)|0,a=a+Math.imul(j,xt)|0;var ni=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(ni>>>26)|0,ni&=67108863,o=Math.imul(rt,wt),i=Math.imul(rt,yt),i=i+Math.imul(et,wt)|0,a=Math.imul(et,yt),o=o+Math.imul(tt,bt)|0,i=i+Math.imul(tt,xt)|0,i=i+Math.imul(it,bt)|0,a=a+Math.imul(it,xt)|0;var oi=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(oi>>>26)|0,oi&=67108863,o=Math.imul(rt,bt),i=Math.imul(rt,xt),i=i+Math.imul(et,bt)|0,a=Math.imul(et,xt);var si=(u+o|0)+((i&8191)<<13)|0;return u=(a+(i>>>13)|0)+(si>>>26)|0,si&=67108863,l[0]=Wt,l[1]=Ut,l[2]=zt,l[3]=Ht,l[4]=Vt,l[5]=Jt,l[6]=Qt,l[7]=Xt,l[8]=Yt,l[9]=$t,l[10]=Gt,l[11]=jt,l[12]=ti,l[13]=ii,l[14]=ri,l[15]=ei,l[16]=ni,l[17]=oi,l[18]=si,u!==0&&(l[19]=u,e.length++),e};Math.imul||(Z=U);function E(h,t,r){r.negative=t.negative^h.negative,r.length=h.length+t.length;for(var e=0,n=0,s=0;s<r.length-1;s++){var l=n;n=0;for(var u=e&67108863,o=Math.min(s,t.length-1),i=Math.max(0,s-h.length+1);i<=o;i++){var a=s-i,p=h.words[a]|0,v=t.words[i]|0,g=p*v,b=g&67108863;l=l+(g/67108864|0)|0,b=b+u|0,u=b&67108863,l=l+(b>>>26)|0,n+=l>>>26,l&=67108863}r.words[s]=u,e=l,l=n}return e!==0?r.words[s]=e:r.length--,r._strip()}function R(h,t,r){return E(h,t,r)}f.prototype.mulTo=function(t,r){var e,n=this.length+t.length;return this.length===10&&t.length===10?e=Z(this,t,r):n<63?e=U(this,t,r):n<1024?e=E(this,t,r):e=R(this,t,r),e};function B(h,t){this.x=h,this.y=t}B.prototype.makeRBT=function(t){for(var r=new Array(t),e=f.prototype._countBits(t)-1,n=0;n<t;n++)r[n]=this.revBin(n,e,t);return r},B.prototype.revBin=function(t,r,e){if(t===0||t===e-1)return t;for(var n=0,s=0;s<r;s++)n|=(t&1)<<r-s-1,t>>=1;return n},B.prototype.permute=function(t,r,e,n,s,l){for(var u=0;u<l;u++)n[u]=r[t[u]],s[u]=e[t[u]]},B.prototype.transform=function(t,r,e,n,s,l){this.permute(l,t,r,e,n,s);for(var u=1;u<s;u<<=1)for(var o=u<<1,i=Math.cos(2*Math.PI/o),a=Math.sin(2*Math.PI/o),p=0;p<s;p+=o)for(var v=i,g=a,b=0;b<u;b++){var k=e[p+b],F=n[p+b],Ot=e[p+b+u],K=n[p+b+u],N=v*Ot-g*K;K=v*K+g*Ot,Ot=N,e[p+b]=k+Ot,n[p+b]=F+K,e[p+b+u]=k-Ot,n[p+b+u]=F-K,b!==o&&(N=i*v-a*g,g=i*g+a*v,v=N)}},B.prototype.guessLen13b=function(t,r){var e=Math.max(r,t)|1,n=e&1,s=0;for(e=e/2|0;e;e=e>>>1)s++;return 1<<s+1+n},B.prototype.conjugate=function(t,r,e){if(!(e<=1))for(var n=0;n<e/2;n++){var s=t[n];t[n]=t[e-n-1],t[e-n-1]=s,s=r[n],r[n]=-r[e-n-1],r[e-n-1]=-s}},B.prototype.normalize13b=function(t,r){for(var e=0,n=0;n<r/2;n++){var s=Math.round(t[2*n+1]/r)*8192+Math.round(t[2*n]/r)+e;t[n]=s&67108863,s<67108864?e=0:e=s/67108864|0}return t},B.prototype.convert13b=function(t,r,e,n){for(var s=0,l=0;l<r;l++)s=s+(t[l]|0),e[2*l]=s&8191,s=s>>>13,e[2*l+1]=s&8191,s=s>>>13;for(l=2*r;l<n;++l)e[l]=0;d(s===0),d((s&-8192)===0)},B.prototype.stub=function(t){for(var r=new Array(t),e=0;e<t;e++)r[e]=0;return r},B.prototype.mulp=function(t,r,e){var n=2*this.guessLen13b(t.length,r.length),s=this.makeRBT(n),l=this.stub(n),u=new Array(n),o=new Array(n),i=new Array(n),a=new Array(n),p=new Array(n),v=new Array(n),g=e.words;g.length=n,this.convert13b(t.words,t.length,u,n),this.convert13b(r.words,r.length,a,n),this.transform(u,l,o,i,n,s),this.transform(a,l,p,v,n,s);for(var b=0;b<n;b++){var k=o[b]*p[b]-i[b]*v[b];i[b]=o[b]*v[b]+i[b]*p[b],o[b]=k}return this.conjugate(o,i,n),this.transform(o,i,g,l,n,s),this.conjugate(g,l,n),this.normalize13b(g,n),e.negative=t.negative^r.negative,e.length=t.length+r.length,e._strip()},f.prototype.mul=function(t){var r=new f(null);return r.words=new Array(this.length+t.length),this.mulTo(t,r)},f.prototype.mulf=function(t){var r=new f(null);return r.words=new Array(this.length+t.length),R(this,t,r)},f.prototype.imul=function(t){return this.clone().mulTo(t,this)},f.prototype.imuln=function(t){var r=t<0;r&&(t=-t),d(typeof t=="number"),d(t<67108864);for(var e=0,n=0;n<this.length;n++){var s=(this.words[n]|0)*t,l=(s&67108863)+(e&67108863);e>>=26,e+=s/67108864|0,e+=l>>>26,this.words[n]=l&67108863}return e!==0&&(this.words[n]=e,this.length++),this.length=t===0?1:this.length,r?this.ineg():this},f.prototype.muln=function(t){return this.clone().imuln(t)},f.prototype.sqr=function(){return this.mul(this)},f.prototype.isqr=function(){return this.imul(this.clone())},f.prototype.pow=function(t){var r=W(t);if(r.length===0)return new f(1);for(var e=this,n=0;n<r.length&&r[n]===0;n++,e=e.sqr());if(++n<r.length)for(var s=e.sqr();n<r.length;n++,s=s.sqr())r[n]!==0&&(e=e.mul(s));return e},f.prototype.iushln=function(t){d(typeof t=="number"&&t>=0);var r=t%26,e=(t-r)/26,n=67108863>>>26-r<<26-r,s;if(r!==0){var l=0;for(s=0;s<this.length;s++){var u=this.words[s]&n,o=(this.words[s]|0)-u<<r;this.words[s]=o|l,l=u>>>26-r}l&&(this.words[s]=l,this.length++)}if(e!==0){for(s=this.length-1;s>=0;s--)this.words[s+e]=this.words[s];for(s=0;s<e;s++)this.words[s]=0;this.length+=e}return this._strip()},f.prototype.ishln=function(t){return d(this.negative===0),this.iushln(t)},f.prototype.iushrn=function(t,r,e){d(typeof t=="number"&&t>=0);var n;r?n=(r-r%26)/26:n=0;var s=t%26,l=Math.min((t-s)/26,this.length),u=67108863^67108863>>>s<<s,o=e;if(n-=l,n=Math.max(0,n),o){for(var i=0;i<l;i++)o.words[i]=this.words[i];o.length=l}if(l!==0)if(this.length>l)for(this.length-=l,i=0;i<this.length;i++)this.words[i]=this.words[i+l];else this.words[0]=0,this.length=1;var a=0;for(i=this.length-1;i>=0&&(a!==0||i>=n);i--){var p=this.words[i]|0;this.words[i]=a<<26-s|p>>>s,a=p&u}return o&&a!==0&&(o.words[o.length++]=a),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},f.prototype.ishrn=function(t,r,e){return d(this.negative===0),this.iushrn(t,r,e)},f.prototype.shln=function(t){return this.clone().ishln(t)},f.prototype.ushln=function(t){return this.clone().iushln(t)},f.prototype.shrn=function(t){return this.clone().ishrn(t)},f.prototype.ushrn=function(t){return this.clone().iushrn(t)},f.prototype.testn=function(t){d(typeof t=="number"&&t>=0);var r=t%26,e=(t-r)/26,n=1<<r;if(this.length<=e)return!1;var s=this.words[e];return!!(s&n)},f.prototype.imaskn=function(t){d(typeof t=="number"&&t>=0);var r=t%26,e=(t-r)/26;if(d(this.negative===0,"imaskn works only with positive numbers"),this.length<=e)return this;if(r!==0&&e++,this.length=Math.min(e,this.length),r!==0){var n=67108863^67108863>>>r<<r;this.words[this.length-1]&=n}return this._strip()},f.prototype.maskn=function(t){return this.clone().imaskn(t)},f.prototype.iaddn=function(t){return d(typeof t=="number"),d(t<67108864),t<0?this.isubn(-t):this.negative!==0?this.length===1&&(this.words[0]|0)<=t?(this.words[0]=t-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},f.prototype._iaddn=function(t){this.words[0]+=t;for(var r=0;r<this.length&&this.words[r]>=67108864;r++)this.words[r]-=67108864,r===this.length-1?this.words[r+1]=1:this.words[r+1]++;return this.length=Math.max(this.length,r+1),this},f.prototype.isubn=function(t){if(d(typeof t=="number"),d(t<67108864),t<0)return this.iaddn(-t);if(this.negative!==0)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var r=0;r<this.length&&this.words[r]<0;r++)this.words[r]+=67108864,this.words[r+1]-=1;return this._strip()},f.prototype.addn=function(t){return this.clone().iaddn(t)},f.prototype.subn=function(t){return this.clone().isubn(t)},f.prototype.iabs=function(){return this.negative=0,this},f.prototype.abs=function(){return this.clone().iabs()},f.prototype._ishlnsubmul=function(t,r,e){var n=t.length+e,s;this._expand(n);var l,u=0;for(s=0;s<t.length;s++){l=(this.words[s+e]|0)+u;var o=(t.words[s]|0)*r;l-=o&67108863,u=(l>>26)-(o/67108864|0),this.words[s+e]=l&67108863}for(;s<this.length-e;s++)l=(this.words[s+e]|0)+u,u=l>>26,this.words[s+e]=l&67108863;if(u===0)return this._strip();for(d(u===-1),u=0,s=0;s<this.length;s++)l=-(this.words[s]|0)+u,u=l>>26,this.words[s]=l&67108863;return this.negative=1,this._strip()},f.prototype._wordDiv=function(t,r){var e=this.length-t.length,n=this.clone(),s=t,l=s.words[s.length-1]|0,u=this._countBits(l);e=26-u,e!==0&&(s=s.ushln(e),n.iushln(e),l=s.words[s.length-1]|0);var o=n.length-s.length,i;if(r!=="mod"){i=new f(null),i.length=o+1,i.words=new Array(i.length);for(var a=0;a<i.length;a++)i.words[a]=0}var p=n.clone()._ishlnsubmul(s,1,o);p.negative===0&&(n=p,i&&(i.words[o]=1));for(var v=o-1;v>=0;v--){var g=(n.words[s.length+v]|0)*67108864+(n.words[s.length+v-1]|0);for(g=Math.min(g/l|0,67108863),n._ishlnsubmul(s,g,v);n.negative!==0;)g--,n.negative=0,n._ishlnsubmul(s,1,v),n.isZero()||(n.negative^=1);i&&(i.words[v]=g)}return i&&i._strip(),n._strip(),r!=="div"&&e!==0&&n.iushrn(e),{div:i||null,mod:n}},f.prototype.divmod=function(t,r,e){if(d(!t.isZero()),this.isZero())return{div:new f(0),mod:new f(0)};var n,s,l;return this.negative!==0&&t.negative===0?(l=this.neg().divmod(t,r),r!=="mod"&&(n=l.div.neg()),r!=="div"&&(s=l.mod.neg(),e&&s.negative!==0&&s.iadd(t)),{div:n,mod:s}):this.negative===0&&t.negative!==0?(l=this.divmod(t.neg(),r),r!=="mod"&&(n=l.div.neg()),{div:n,mod:l.mod}):(this.negative&t.negative)!==0?(l=this.neg().divmod(t.neg(),r),r!=="div"&&(s=l.mod.neg(),e&&s.negative!==0&&s.isub(t)),{div:l.div,mod:s}):t.length>this.length||this.cmp(t)<0?{div:new f(0),mod:this}:t.length===1?r==="div"?{div:this.divn(t.words[0]),mod:null}:r==="mod"?{div:null,mod:new f(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new f(this.modrn(t.words[0]))}:this._wordDiv(t,r)},f.prototype.div=function(t){return this.divmod(t,"div",!1).div},f.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},f.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},f.prototype.divRound=function(t){var r=this.divmod(t);if(r.mod.isZero())return r.div;var e=r.div.negative!==0?r.mod.isub(t):r.mod,n=t.ushrn(1),s=t.andln(1),l=e.cmp(n);return l<0||s===1&&l===0?r.div:r.div.negative!==0?r.div.isubn(1):r.div.iaddn(1)},f.prototype.modrn=function(t){var r=t<0;r&&(t=-t),d(t<=67108863);for(var e=(1<<26)%t,n=0,s=this.length-1;s>=0;s--)n=(e*n+(this.words[s]|0))%t;return r?-n:n},f.prototype.modn=function(t){return this.modrn(t)},f.prototype.idivn=function(t){var r=t<0;r&&(t=-t),d(t<=67108863);for(var e=0,n=this.length-1;n>=0;n--){var s=(this.words[n]|0)+e*67108864;this.words[n]=s/t|0,e=s%t}return this._strip(),r?this.ineg():this},f.prototype.divn=function(t){return this.clone().idivn(t)},f.prototype.egcd=function(t){d(t.negative===0),d(!t.isZero());var r=this,e=t.clone();r.negative!==0?r=r.umod(t):r=r.clone();for(var n=new f(1),s=new f(0),l=new f(0),u=new f(1),o=0;r.isEven()&&e.isEven();)r.iushrn(1),e.iushrn(1),++o;for(var i=e.clone(),a=r.clone();!r.isZero();){for(var p=0,v=1;(r.words[0]&v)===0&&p<26;++p,v<<=1);if(p>0)for(r.iushrn(p);p-- >0;)(n.isOdd()||s.isOdd())&&(n.iadd(i),s.isub(a)),n.iushrn(1),s.iushrn(1);for(var g=0,b=1;(e.words[0]&b)===0&&g<26;++g,b<<=1);if(g>0)for(e.iushrn(g);g-- >0;)(l.isOdd()||u.isOdd())&&(l.iadd(i),u.isub(a)),l.iushrn(1),u.iushrn(1);r.cmp(e)>=0?(r.isub(e),n.isub(l),s.isub(u)):(e.isub(r),l.isub(n),u.isub(s))}return{a:l,b:u,gcd:e.iushln(o)}},f.prototype._invmp=function(t){d(t.negative===0),d(!t.isZero());var r=this,e=t.clone();r.negative!==0?r=r.umod(t):r=r.clone();for(var n=new f(1),s=new f(0),l=e.clone();r.cmpn(1)>0&&e.cmpn(1)>0;){for(var u=0,o=1;(r.words[0]&o)===0&&u<26;++u,o<<=1);if(u>0)for(r.iushrn(u);u-- >0;)n.isOdd()&&n.iadd(l),n.iushrn(1);for(var i=0,a=1;(e.words[0]&a)===0&&i<26;++i,a<<=1);if(i>0)for(e.iushrn(i);i-- >0;)s.isOdd()&&s.iadd(l),s.iushrn(1);r.cmp(e)>=0?(r.isub(e),n.isub(s)):(e.isub(r),s.isub(n))}var p;return r.cmpn(1)===0?p=n:p=s,p.cmpn(0)<0&&p.iadd(t),p},f.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var r=this.clone(),e=t.clone();r.negative=0,e.negative=0;for(var n=0;r.isEven()&&e.isEven();n++)r.iushrn(1),e.iushrn(1);do{for(;r.isEven();)r.iushrn(1);for(;e.isEven();)e.iushrn(1);var s=r.cmp(e);if(s<0){var l=r;r=e,e=l}else if(s===0||e.cmpn(1)===0)break;r.isub(e)}while(!0);return e.iushln(n)},f.prototype.invm=function(t){return this.egcd(t).a.umod(t)},f.prototype.isEven=function(){return(this.words[0]&1)===0},f.prototype.isOdd=function(){return(this.words[0]&1)===1},f.prototype.andln=function(t){return this.words[0]&t},f.prototype.bincn=function(t){d(typeof t=="number");var r=t%26,e=(t-r)/26,n=1<<r;if(this.length<=e)return this._expand(e+1),this.words[e]|=n,this;for(var s=n,l=e;s!==0&&l<this.length;l++){var u=this.words[l]|0;u+=s,s=u>>>26,u&=67108863,this.words[l]=u}return s!==0&&(this.words[l]=s,this.length++),this},f.prototype.isZero=function(){return this.length===1&&this.words[0]===0},f.prototype.cmpn=function(t){var r=t<0;if(this.negative!==0&&!r)return-1;if(this.negative===0&&r)return 1;this._strip();var e;if(this.length>1)e=1;else{r&&(t=-t),d(t<=67108863,"Number is too big");var n=this.words[0]|0;e=n===t?0:n<t?-1:1}return this.negative!==0?-e|0:e},f.prototype.cmp=function(t){if(this.negative!==0&&t.negative===0)return-1;if(this.negative===0&&t.negative!==0)return 1;var r=this.ucmp(t);return this.negative!==0?-r|0:r},f.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var r=0,e=this.length-1;e>=0;e--){var n=this.words[e]|0,s=t.words[e]|0;if(n!==s){n<s?r=-1:n>s&&(r=1);break}}return r},f.prototype.gtn=function(t){return this.cmpn(t)===1},f.prototype.gt=function(t){return this.cmp(t)===1},f.prototype.gten=function(t){return this.cmpn(t)>=0},f.prototype.gte=function(t){return this.cmp(t)>=0},f.prototype.ltn=function(t){return this.cmpn(t)===-1},f.prototype.lt=function(t){return this.cmp(t)===-1},f.prototype.lten=function(t){return this.cmpn(t)<=0},f.prototype.lte=function(t){return this.cmp(t)<=0},f.prototype.eqn=function(t){return this.cmpn(t)===0},f.prototype.eq=function(t){return this.cmp(t)===0},f.red=function(t){return new T(t)},f.prototype.toRed=function(t){return d(!this.red,"Already a number in reduction context"),d(this.negative===0,"red works only with positives"),t.convertTo(this)._forceRed(t)},f.prototype.fromRed=function(){return d(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},f.prototype._forceRed=function(t){return this.red=t,this},f.prototype.forceRed=function(t){return d(!this.red,"Already a number in reduction context"),this._forceRed(t)},f.prototype.redAdd=function(t){return d(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},f.prototype.redIAdd=function(t){return d(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},f.prototype.redSub=function(t){return d(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},f.prototype.redISub=function(t){return d(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},f.prototype.redShl=function(t){return d(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},f.prototype.redMul=function(t){return d(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},f.prototype.redIMul=function(t){return d(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},f.prototype.redSqr=function(){return d(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},f.prototype.redISqr=function(){return d(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},f.prototype.redSqrt=function(){return d(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},f.prototype.redInvm=function(){return d(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},f.prototype.redNeg=function(){return d(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},f.prototype.redPow=function(t){return d(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var I={k256:null,p224:null,p192:null,p25519:null};function O(h,t){this.name=h,this.p=new f(t,16),this.n=this.p.bitLength(),this.k=new f(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}O.prototype._tmp=function(){var t=new f(null);return t.words=new Array(Math.ceil(this.n/13)),t},O.prototype.ireduce=function(t){var r=t,e;do this.split(r,this.tmp),r=this.imulK(r),r=r.iadd(this.tmp),e=r.bitLength();while(e>this.n);var n=e<this.n?-1:r.ucmp(this.p);return n===0?(r.words[0]=0,r.length=1):n>0?r.isub(this.p):r.strip!==void 0?r.strip():r._strip(),r},O.prototype.split=function(t,r){t.iushrn(this.n,0,r)},O.prototype.imulK=function(t){return t.imul(this.k)};function Dt(){O.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}_(Dt,O),Dt.prototype.split=function(t,r){for(var e=4194303,n=Math.min(t.length,9),s=0;s<n;s++)r.words[s]=t.words[s];if(r.length=n,t.length<=9){t.words[0]=0,t.length=1;return}var l=t.words[9];for(r.words[r.length++]=l&e,s=10;s<t.length;s++){var u=t.words[s]|0;t.words[s-10]=(u&e)<<4|l>>>22,l=u}l>>>=22,t.words[s-10]=l,l===0&&t.length>10?t.length-=10:t.length-=9},Dt.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var r=0,e=0;e<t.length;e++){var n=t.words[e]|0;r+=n*977,t.words[e]=r&67108863,r=n*64+(r/67108864|0)}return t.words[t.length-1]===0&&(t.length--,t.words[t.length-1]===0&&t.length--),t};function St(){O.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}_(St,O);function Rt(){O.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}_(Rt,O);function qt(){O.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}_(qt,O),qt.prototype.imulK=function(t){for(var r=0,e=0;e<t.length;e++){var n=(t.words[e]|0)*19+r,s=n&67108863;n>>>=26,t.words[e]=s,r=n}return r!==0&&(t.words[t.length++]=r),t},f._prime=function(t){if(I[t])return I[t];var r;if(t==="k256")r=new Dt;else if(t==="p224")r=new St;else if(t==="p192")r=new Rt;else if(t==="p25519")r=new qt;else throw new Error("Unknown prime "+t);return I[t]=r,r};function T(h){if(typeof h=="string"){var t=f._prime(h);this.m=t.p,this.prime=t}else d(h.gtn(1),"modulus must be greater than 1"),this.m=h,this.prime=null}T.prototype._verify1=function(t){d(t.negative===0,"red works only with positives"),d(t.red,"red works only with red numbers")},T.prototype._verify2=function(t,r){d((t.negative|r.negative)===0,"red works only with positives"),d(t.red&&t.red===r.red,"red works only with red numbers")},T.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(A(t,t.umod(this.m)._forceRed(this)),t)},T.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},T.prototype.add=function(t,r){this._verify2(t,r);var e=t.add(r);return e.cmp(this.m)>=0&&e.isub(this.m),e._forceRed(this)},T.prototype.iadd=function(t,r){this._verify2(t,r);var e=t.iadd(r);return e.cmp(this.m)>=0&&e.isub(this.m),e},T.prototype.sub=function(t,r){this._verify2(t,r);var e=t.sub(r);return e.cmpn(0)<0&&e.iadd(this.m),e._forceRed(this)},T.prototype.isub=function(t,r){this._verify2(t,r);var e=t.isub(r);return e.cmpn(0)<0&&e.iadd(this.m),e},T.prototype.shl=function(t,r){return this._verify1(t),this.imod(t.ushln(r))},T.prototype.imul=function(t,r){return this._verify2(t,r),this.imod(t.imul(r))},T.prototype.mul=function(t,r){return this._verify2(t,r),this.imod(t.mul(r))},T.prototype.isqr=function(t){return this.imul(t,t.clone())},T.prototype.sqr=function(t){return this.mul(t,t)},T.prototype.sqrt=function(t){if(t.isZero())return t.clone();var r=this.m.andln(3);if(d(r%2===1),r===3){var e=this.m.add(new f(1)).iushrn(2);return this.pow(t,e)}for(var n=this.m.subn(1),s=0;!n.isZero()&&n.andln(1)===0;)s++,n.iushrn(1);d(!n.isZero());var l=new f(1).toRed(this),u=l.redNeg(),o=this.m.subn(1).iushrn(1),i=this.m.bitLength();for(i=new f(2*i*i).toRed(this);this.pow(i,o).cmp(u)!==0;)i.redIAdd(u);for(var a=this.pow(i,n),p=this.pow(t,n.addn(1).iushrn(1)),v=this.pow(t,n),g=s;v.cmp(l)!==0;){for(var b=v,k=0;b.cmp(l)!==0;k++)b=b.redSqr();d(k<g);var F=this.pow(a,new f(1).iushln(g-k-1));p=p.redMul(F),a=F.redSqr(),v=v.redMul(a),g=k}return p},T.prototype.invm=function(t){var r=t._invmp(this.m);return r.negative!==0?(r.negative=0,this.imod(r).redNeg()):this.imod(r)},T.prototype.pow=function(t,r){if(r.isZero())return new f(1).toRed(this);if(r.cmpn(1)===0)return t.clone();var e=4,n=new Array(1<<e);n[0]=new f(1).toRed(this),n[1]=t;for(var s=2;s<n.length;s++)n[s]=this.mul(n[s-1],t);var l=n[0],u=0,o=0,i=r.bitLength()%26;for(i===0&&(i=26),s=r.length-1;s>=0;s--){for(var a=r.words[s],p=i-1;p>=0;p--){var v=a>>p&1;if(l!==n[0]&&(l=this.sqr(l)),v===0&&u===0){o=0;continue}u<<=1,u|=v,o++,!(o!==e&&(s!==0||p!==0))&&(l=this.mul(l,n[u]),o=0,u=0)}i=26}return l},T.prototype.convertTo=function(t){var r=t.umod(this.m);return r===t?r.clone():r},T.prototype.convertFrom=function(t){var r=t.clone();return r.red=null,r},f.mont=function(t){return new Bt(t)};function Bt(h){T.call(this,h),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new f(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}_(Bt,T),Bt.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},Bt.prototype.convertFrom=function(t){var r=this.imod(t.mul(this.rinv));return r.red=null,r},Bt.prototype.imul=function(t,r){if(t.isZero()||r.isZero())return t.words[0]=0,t.length=1,t;var e=t.imul(r),n=e.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),s=e.isub(n).iushrn(this.shift),l=s;return s.cmp(this.m)>=0?l=s.isub(this.m):s.cmpn(0)<0&&(l=s.iadd(this.m)),l._forceRed(this)},Bt.prototype.mul=function(t,r){if(t.isZero()||r.isZero())return new f(0)._forceRed(this);var e=t.mul(r),n=e.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),s=e.isub(n).iushrn(this.shift),l=s;return s.cmp(this.m)>=0?l=s.isub(this.m):s.cmpn(0)<0&&(l=s.iadd(this.m)),l._forceRed(this)},Bt.prototype.invm=function(t){var r=this.imod(t._invmp(this.m).mul(this.r2));return r._forceRed(this)}})(typeof fi>"u"||fi,Ii)});var Gi={};Qi(Gi,{CetusDlmmZapSDK:()=>Pt,ZapError:()=>Et,ZapErrorCode:()=>ui,ZapModule:()=>Tt,calcExactSwapAmount:()=>pi,calculateLiquidityAmountEnough:()=>mi,calculateLiquidityAmountSide:()=>Yi,default:()=>$i,defaultSwapSlippage:()=>Zt,handleError:()=>di,handleMessageError:()=>Ct,zapMainnet:()=>ai,zapTestnet:()=>hi});module.exports=Xi(Gi);var kt=require("@cetusprotocol/aggregator-sdk"),vi=require("@mysten/sui/client"),gi=require("@mysten/sui/utils"),Zi=require("@cetusprotocol/dlmm-sdk"),Ni=require("@cetusprotocol/common-sdk");var Ft=require("@cetusprotocol/common-sdk"),ai={env:"mainnet",full_rpc_url:Ft.FullRpcUrlMainnet,graph_rpc_url:Ft.GraphRpcUrlMainnet,aggregator_url:"https://api-sui.cetus.zone/router_v3",providers:[]};var Kt=require("@cetusprotocol/common-sdk"),hi={env:"testnet",full_rpc_url:Kt.FullRpcUrlTestnet,graph_rpc_url:Kt.GraphRpcUrlTestnet,aggregator_url:"https://api-sui.devcetus.com/router_v3",providers:["CETUS","DEEPBOOK","KRIYA","KRIYAV3","FLOWX","FLOWXV3","AFTERMATH","TURBOS","HAEDAL","VOLO","AFSUI"]};var ci=require("@mysten/sui/transactions"),Ki=Pi(li()),c=require("@cetusprotocol/common-sdk");var Fi=require("@cetusprotocol/common-sdk"),ui=(M=>(M.UnsupportedDepositMode="UnsupportedDepositMode",M.PositionIdUndefined="PositionIdUndefined",M.ParameterError="ParameterError",M.ReachMaxIterations="ReachMaxIterations",M.BestLiquidityIsZero="BestLiquidityIsZero",M.SwapAmountError="SwapAmountError",M.AggregatorError="AggregatorError",M))(ui||{}),Et=class extends Fi.BaseError{constructor(m,d,_){super(m,d||"UnknownError",_)}static isZapErrorCode(m,d){return this.isErrorCode(m,d)}},di=(x,m,d)=>{throw new Et(m.message,x,d)},Ct=(x,m,d)=>{throw new Et(m,x,d)};var Zt=.005;var Lt=Pi(li()),At=require("@cetusprotocol/common-sdk");function mi(x,m,d,_,f,S,w){let M=w?new Lt.default(x):new Lt.default(m),y=At.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(_,f,M,w,!0,S,new Lt.default(d)),A=w?M.toString():y.coin_amount_a.toString(),L=w?y.coin_amount_b.toString():M.toString(),P=(0,At.d)(x).sub(A),q=(0,At.d)(m).sub(L);return{is_enough_amount:w?q.gte(0):P.gte(0),use_amount_a:A,use_amount_b:L,liquidity:y.liquidity_amount,amount_limit_a:y.coin_amount_limit_a,amount_limit_b:y.coin_amount_limit_b,remain_amount:w?q:P}}function Yi(x,m,d,_,f,S,w){let M=At.TickMath.sqrtPriceX64ToTickIndex(new Lt.default(d)),y=w;M<_?y=!0:M>f&&(y=!1);let A=mi(x,m,d,_,f,S,y);return A.is_enough_amount||(y=!y,A=mi(x,m,d,_,f,S,y)),{fix_liquidity_amount_a:y,...A}}function pi(x,m,d,_){let f=(0,At.d)(x),S=(0,At.d)(d),w=(0,At.d)(_),M=f,y=m?f:(0,At.d)(0),A=m?(0,At.d)(0):f,L=w,P=(0,At.d)(w).mul(.999),q=(0,At.d)(0),D=M,C=null;function W(E){if(m){let R=y.minus(E),B=A.plus(E.mul(S));return{A:R,B,R:B.div(R)}}else{let R=y.plus(E.mul(S)),B=A.minus(E);return{A:R,B,R:R.div(B)}}}for(let E=0;E<120;E++){let R=q.plus(D).div(2),{A:B,B:I,R:O}=W(R);if(B.lte(0)||I.lte(0)){D=R;continue}if(O.gt(L))D=R;else if(O.lt(P))q=R;else{if(C=R,(0,At.d)(P).eq(0))break;D=R}}if(!C)return{swap_amount:"0",final_amount_a:y.toFixed(0),final_amount_b:A.toFixed(0)};let{A:U,B:Z}=W(C);return{swap_amount:C.toFixed(0),final_amount_a:U.toFixed(0),final_amount_b:Z.toFixed(0)}}var Nt=require("@cetusprotocol/dlmm-sdk"),Tt=class{constructor(m){this._sdk=m}get sdk(){return this._sdk}async calculateBalanceSwapAmountWithoutActiveId(m,d){let{fix_amount_a:_,coin_amount:f}=d,{bin_step:S,pool_id:w,active_id:M,lower_bin_id:y,upper_bin_id:A,active_bin_of_pool:L,strategy_type:P}=m,q=await this._sdk.DlmmSDK.Pool.getPool(w,!1),D,C=_,W=f;return M>A?(C=!1,_?(D=await this.findRouters(q.coin_type_a,q.coin_type_b,f),W=(0,c.d)(D.swap_out_amount).mul(1-.001).toFixed(0)):W=f):M<y&&(C=!0,_?W=f:(D=await this.findRouters(q.coin_type_b,q.coin_type_a,f),W=(0,c.d)(D.swap_out_amount).mul(1-.001).toFixed(0))),{liquidity_info:await this._sdk.DlmmSDK.Position.calculateAddLiquidityInfo({pool_id:w,coin_amount:W,fix_amount_a:C,active_id:M,bin_step:S,lower_bin_id:y,upper_bin_id:A,active_bin_of_pool:L,strategy_type:P}),swap_result:D}}async calculateBalanceSwapAmount(m,d){let{fix_amount_a:_,coin_amount:f}=d,{bin_step:S,pool_id:w,active_id:M,lower_bin_id:y,upper_bin_id:A,active_bin_of_pool:L,strategy_type:P}=m;if(M>A||M<y)return this.calculateBalanceSwapAmountWithoutActiveId(m,d);let q=await this._sdk.DlmmSDK.Position.calculateAddLiquidityInfo({pool_id:w,coin_amount:f,fix_amount_a:_,active_id:M,bin_step:S,lower_bin_id:y,upper_bin_id:A,active_bin_of_pool:L,strategy_type:P}),{amount_a:D,amount_b:C}=q,W=_?(0,c.d)(C).div(D):(0,c.d)(D).div(C),U=_?Nt.BinUtils.getPricePerLamportFromBinId(M,S):(0,c.d)(1).div(Nt.BinUtils.getPricePerLamportFromBinId(M,S)).toString(),Z=await this._sdk.DlmmSDK.Pool.getPool(w,!1);try{let t=await this.findRouters(_?Z.coin_type_a:Z.coin_type_b,_?Z.coin_type_b:Z.coin_type_a,f);t&&(U=(0,c.d)(t.swap_out_amount).div(t.swap_in_amount).toString())}catch{}let{swap_amount:E,final_amount_a:R,final_amount_b:B}=pi(f,_,U,W.toString());console.log("\u{1F680} ~ ZapModule ~ swap_amount:",{swap_amount:E,final_amount_a:R,final_amount_b:B,target_rate:W,real_price:U,coin_amount:f,fix_amount_a:_});let I=E||"0",O,Dt,St,Rt=0,qt=.02,T,Bt,h;do{let t=(0,c.d)(f).sub(I).toFixed(0);St=await this.findRouters(_?Z.coin_type_a:Z.coin_type_b,_?Z.coin_type_b:Z.coin_type_a,I);let r=(0,c.d)(St.swap_out_amount).toFixed(0),e=await this._sdk.DlmmSDK.Position.calculateAddLiquidityInfo({pool_id:w,coin_amount:t,fix_amount_a:_,active_id:M,bin_step:S,lower_bin_id:y,upper_bin_id:A,active_bin_of_pool:L,strategy_type:P}),{amount_a:n,amount_b:s}=e,l=_?s:n,u=(0,c.d)(r).sub(l).div(r);if(u.gt(0)&&(h===void 0||u.lt(h))&&(T=St,Bt=e,h=u),(0,c.d)(r).gt(l))if((0,c.d)(u).gt(qt))console.log("calculateBalanceSwapAmount -: ",{swap_amount_in:I,real_remain_rate:u.toString(),cached_real_remain_rate:h?.toString(),temp_swap_result:St,deposit_amount_other:l,count:Rt}),I=(0,c.d)(I).mul(1-.01).toFixed(0),Rt++;else{O=St,Dt=e;break}else I=(0,c.d)(I).mul(1+.01).toFixed(0),I=Math.min(Number((0,c.d)(f).mul(1-1e-4).toFixed(0)),Number(I)).toString(),console.log("calculateBalanceSwapAmount +: ",{swap_amount_in:I,real_remain_rate:u.toString(),cached_real_remain_rate:h?.toString(),temp_swap_result:St,deposit_amount_other:l,count:Rt}),Rt++;if(Rt>5)break}while(!O&&(0,c.d)(I).gt(0));if(O===void 0&&T&&(O=T,Dt=Bt),O===void 0&&St){let{swap_out_amount:t}=St,r=await this._sdk.DlmmSDK.Position.calculateAddLiquidityInfo({pool_id:w,coin_amount:(0,c.d)(t).sub(1-.001).toFixed(0),fix_amount_a:!_,active_id:M,bin_step:S,lower_bin_id:y,upper_bin_id:A,active_bin_of_pool:L,strategy_type:P});O=St,Dt=r}return{swap_result:O,liquidity_info:Dt}}async preCalculateDepositAmount(m,d){let{fix_amount_a:_,coin_amount:f}=d;console.log("\u{1F680} ~ ZapModule ~ preCalculateDepositAmount ~ options:",{options:m,mode_options:d});let{liquidity_info:S,swap_result:w}=await this.calculateBalanceSwapAmount(m,d);return S===void 0?Ct("SwapAmountError","Best liquidity info is undefined",{[c.DETAILS_KEYS.METHOD_NAME]:"preCalculateDepositAmount"}):{bin_infos:S,swap_result:w,fix_amount_a:_,coin_amount:f}}async buildDepositPayload(m,d){let{swap_slippage:_=Zt,bin_step:f,pool_id:S,active_id:w,lower_bin_id:M,upper_bin_id:y,strategy_type:A,deposit_obj:L,slippage:P,pos_obj:q}=m,{fix_amount_a:D,coin_amount:C,swap_result:W,bin_infos:U}=L;d=d||new ci.Transaction;let Z=await this._sdk.DlmmSDK.Pool.getPool(S,!1),{coin_type_a:E,coin_type_b:R}=Z,B,I;if(W){let O=D?E:R,{swap_in_amount:Dt,route_obj:St}=W,Rt=c.CoinAssist.buildCoinWithBalance(BigInt(Dt),O,d),qt={router:St,slippage:_,txb:d,inputCoin:Rt},T=await this._sdk.AggregatorClient.fixableRouterSwapV3(qt);D?(B=c.CoinAssist.buildCoinWithBalance(BigInt(U.amount_a),E,d),I=T):(B=T,I=c.CoinAssist.buildCoinWithBalance(BigInt(U.amount_b),R,d))}if(q){let O={pool_id:S,bin_infos:U,coin_type_a:E,coin_type_b:R,active_id:w,strategy_type:A,max_price_slippage:P,bin_step:f,use_bin_infos:!1,position_id:q.pos_id,collect_fee:q.collect_fee,reward_coins:q.collect_rewarder_types,coin_object_id_a:B,coin_object_id_b:I};this._sdk.DlmmSDK.Position.addLiquidityPayload(O,d)}else{let O={pool_id:S,bin_infos:U,coin_type_a:E,coin_type_b:R,lower_bin_id:M,upper_bin_id:y,active_id:w,strategy_type:A,use_bin_infos:!1,max_price_slippage:P,bin_step:f,coin_object_id_a:B,coin_object_id_b:I};this._sdk.DlmmSDK.Position.addLiquidityPayload(O,d)}return d}async findRouters(m,d,_){let{providers:f}=this._sdk.sdkOptions,S=this._sdk.AggregatorClient;if((0,c.d)(_).lt(1))return Ct("SwapAmountError","Swap amount is less than the minimum precision",{[c.DETAILS_KEYS.METHOD_NAME]:"findRouters"});try{let w={from:m,target:d,amount:new Ki.default(_),byAmountIn:!0,depth:3,providers:f},M=await S.findRouters(w);if(M?.error)return Ct("AggregatorError",`Aggregator findRouters error: ${M?.error}`,{[c.DETAILS_KEYS.METHOD_NAME]:"findRouters",[c.DETAILS_KEYS.REQUEST_PARAMS]:w});if(!M?.paths||M?.paths?.length===0)return Ct("AggregatorError","Aggregator findRouters error: no router",{[c.DETAILS_KEYS.METHOD_NAME]:"findRouters",[c.DETAILS_KEYS.REQUEST_PARAMS]:w});let y=M.amountIn.toString(),A=M.amountOut.toString();return{swap_in_amount:y,swap_out_amount:A,route_obj:M}}catch(w){return console.log("\u{1F680} ~ ZapModule ~ error:",JSON.stringify(w,null,2)),di("AggregatorError",w,{[c.DETAILS_KEYS.METHOD_NAME]:"swapInPools"})}}calculateZapOutAvailableAmount(m){let{is_receive_coin_a:d,mode:_,active_id:f,bin_step:S,remove_bin_range:w,prices:M,coin_decimal_a:y,coin_decimal_b:A}=m,L;if(M){let{coin_a_price:R,coin_b_price:B}=M;L=(0,c.d)(R).div(B).toString()}else L=Nt.BinUtils.getPriceFromBinId(f,S,y,A);let P,q="0",D="0",C="0";w.forEach(R=>{R.bin_id===f&&(P=R),q=(0,c.d)(q).add(R.amount_a).toFixed(0),D=(0,c.d)(D).add(R.amount_b).toFixed(0)});let W=(0,c.d)(q).sub(P?.amount_a||"0").toFixed(0),U=(0,c.d)(D).sub(P?.amount_b||"0").toFixed(0),Z=(0,c.d)((0,c.toDecimalsAmount)((0,c.d)((0,c.fromDecimalsAmount)(q,y)).mul(L).toString(),A)).toFixed(0),E=(0,c.d)((0,c.toDecimalsAmount)((0,c.d)((0,c.fromDecimalsAmount)(D,A)).div(L).toString(),y)).toFixed(0);return _==="OnlyCoinA"?d?C=W:C=Z:_==="OnlyCoinB"?(D=U,d?C=E:C=D):_==="Both"&&(d?C=(0,c.d)(E).add(q).toFixed(0):C=(0,c.d)(Z).add(D).toFixed(0)),{available_amount:C,user_total_amount_a:q,user_total_amount_b:D,active_bin:P,is_receive_coin_a:d}}async preCalculateWithdrawAmount(m){let{is_receive_coin_a:d,remove_bin_range:_,coin_type_a:f,coin_type_b:S,mode:w,expected_receive_amount:M,active_id:y}=m,{available_amount:A,user_total_amount_a:L,user_total_amount_b:P,active_bin:q}=this.calculateZapOutAvailableAmount(m);if((0,c.d)(A).lt((0,c.d)(M)))return Ct("SwapAmountError",`Available amount is less than the expected receive amount: ${A} < ${M}`,{[c.DETAILS_KEYS.METHOD_NAME]:"preCalculateWithdrawAmount",[c.DETAILS_KEYS.REQUEST_PARAMS]:m});let D=(0,c.d)(M).div(A),C;if(w==="Both"){let E=(0,c.d)(L).gt(0),R=E?(0,c.d)(L).mul(D).toFixed(0):(0,c.d)(P).mul(D).toFixed(0);C=this._sdk.DlmmSDK.Position.calculateRemoveLiquidityInfo({bins:_,active_id:y,fix_amount_a:E,coin_amount:R})}else{let E=w==="OnlyCoinA"?(0,c.d)(L).mul(D).toFixed(0):(0,c.d)(P).mul(D).toFixed(0);C=this._sdk.DlmmSDK.Position.calculateRemoveLiquidityInfo({bins:_,active_id:y,is_only_a:w==="OnlyCoinA",coin_amount:E})}let{amount_a:W,amount_b:U}=C,Z;return d&&(0,c.d)(U).gt(0)&&(Z=await this.findRouters(S,f,U)),!d&&(0,c.d)(W).gt(0)&&(Z=await this.findRouters(f,S,W)),{remove_liquidity_info:C,swap_result:Z,mode:w,is_receive_coin_a:d,expected_receive_amount:M,remove_percent:D.toString()}}async buildWithdrawPayload(m){let d=new ci.Transaction,{withdraw_obj:_,swap_slippage:f=Zt,bin_step:S,pool_id:w,active_id:M,collect_fee:y,reward_coins:A,coin_type_a:L,coin_type_b:P,position_id:q,slippage:D,remove_percent:C,is_close_position:W}=m,{remove_liquidity_info:U,swap_result:Z,is_receive_coin_a:E}=_,R={pool_id:w,bin_infos:U,coin_type_a:L,coin_type_b:P,position_id:q,slippage:D,active_id:M,reward_coins:A,collect_fee:y,bin_step:S,remove_percent:Number(C)},{coin_a_obj:B,coin_b_obj:I}=W?this._sdk.DlmmSDK.Position.closePositionNoTransferPayload(R,d):this._sdk.DlmmSDK.Position.removeLiquidityNoTransferPayload(R,d);if(Z){let{route_obj:O}=Z,Dt={router:O,slippage:f,txb:d,inputCoin:E?I:B},St=await this._sdk.AggregatorClient.fixableRouterSwapV3(Dt);E?d.transferObjects([B,St],this._sdk.getSenderAddress()):d.transferObjects([I,St],this._sdk.getSenderAddress())}else d.transferObjects([B,I],this._sdk.getSenderAddress());return d}};var Pt=class x extends Ni.SdkWrapper{constructor(m,d){super(m),this._zapModule=new Tt(this),this._dlmmSDK=d||Zi.CetusDlmmSDK.createSDK({env:m.env,full_rpc_url:m.full_rpc_url}),this._aggregatorClient=new kt.AggregatorClient({signer:(0,gi.normalizeSuiAddress)("0x0"),client:m.sui_client||new vi.SuiClient({url:m.full_rpc_url}),env:m.env==="testnet"?kt.Env.Testnet:kt.Env.Mainnet,pythUrls:m.pyth_urls})}setSenderAddress(m){this._dlmmSDK.setSenderAddress(m)}getSenderAddress(m=!0){return this._dlmmSDK.getSenderAddress(m)}updateProviders(m){if(m.length===0)throw new Error("providers is empty");this._sdkOptions.providers=m}updateFullRpcUrl(m){super.updateFullRpcUrl(m),this._dlmmSDK.updateFullRpcUrl(m),this._aggregatorClient=new kt.AggregatorClient({signer:(0,gi.normalizeSuiAddress)("0x0"),client:new vi.SuiClient({url:m}),env:this._sdkOptions.env==="testnet"?kt.Env.Testnet:kt.Env.Mainnet,pythUrls:this._sdkOptions.pyth_urls})}get DlmmSDK(){return this._dlmmSDK}get AggregatorClient(){return this._aggregatorClient}get Zap(){return this._zapModule}static createSDK(m,d){let{env:_="mainnet",full_rpc_url:f}=m;return _==="mainnet"?x.createCustomSDK({...ai,...m},d):x.createCustomSDK({...hi,...m},d)}static createCustomSDK(m,d){return new x(m,d)}};var $i=Pt;0&&(module.exports={CetusDlmmZapSDK,ZapError,ZapErrorCode,ZapModule,calcExactSwapAmount,calculateLiquidityAmountEnough,calculateLiquidityAmountSide,defaultSwapSlippage,handleError,handleMessageError,zapMainnet,zapTestnet});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|