@cetusprotocol/dlmm-zap-sdk 0.0.1
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 +216 -0
- package/dist/index.d.mts +319 -0
- package/dist/index.d.ts +319 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +38 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var Ki=Object.create;var Ai=Object.defineProperty;var Zi=Object.getOwnPropertyDescriptor;var Ni=Object.getOwnPropertyNames;var Wi=Object.getPrototypeOf,Ui=Object.prototype.hasOwnProperty;var zi=(b=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(b,{get:(m,d)=>(typeof require<"u"?require:m)[d]}):b)(function(b){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+b+'" is not supported')});var Hi=(b,m)=>()=>(m||b((m={exports:{}}).exports,m),m.exports);var Vi=(b,m,d,g)=>{if(m&&typeof m=="object"||typeof m=="function")for(let f of Ni(m))!Ui.call(b,f)&&f!==d&&Ai(b,f,{get:()=>m[f],enumerable:!(g=Zi(m,f))||g.enumerable});return b};var Di=(b,m,d)=>(d=b!=null?Ki(Wi(b)):{},Vi(m||!b||!b.__esModule?Ai(d,"default",{value:b,enumerable:!0}):d,b));var ni=Hi((Oi,ei)=>{"use strict";(function(b,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 b=="object"?b.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=zi("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 M(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=M(h,r);return r-1>=t&&(e|=M(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 w(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=w(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=w(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 x(h,t){h.words=t.words,h.length=t.length,h.negative=t.negative,h.red=t.red}if(f.prototype._move=function(t){x(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)},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 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 y=i-v|0;n=h.words[y]|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,y=n[1]|0,O=y&8191,I=y>>>13,kt=n[2]|0,F=kt&8191,Z=kt>>>13,hi=n[3]|0,U=hi&8191,z=hi>>>13,fi=n[4]|0,H=fi&8191,V=fi>>>13,li=n[5]|0,J=li&8191,Q=li>>>13,ui=n[6]|0,X=ui&8191,Y=ui>>>13,di=n[7]|0,$=di&8191,G=di>>>13,mi=n[8]|0,j=mi&8191,tt=mi>>>13,pi=n[9]|0,it=pi&8191,rt=pi>>>13,ci=s[0]|0,et=ci&8191,nt=ci>>>13,vi=s[1]|0,ot=vi&8191,st=vi>>>13,gi=s[2]|0,at=gi&8191,ht=gi>>>13,_i=s[3]|0,ft=_i&8191,lt=_i>>>13,Mi=s[4]|0,ut=Mi&8191,dt=Mi>>>13,wi=s[5]|0,mt=wi&8191,pt=wi>>>13,yi=s[6]|0,ct=yi&8191,vt=yi>>>13,xi=s[7]|0,gt=xi&8191,_t=xi>>>13,bi=s[8]|0,Mt=bi&8191,wt=bi>>>13,Si=s[9]|0,yt=Si&8191,xt=Si>>>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 Ft=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Ft>>>26)|0,Ft&=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 Kt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Kt>>>26)|0,Kt&=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 Nt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Nt>>>26)|0,Nt&=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 Wt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Wt>>>26)|0,Wt&=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 Ut=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Ut>>>26)|0,Ut&=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 zt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(zt>>>26)|0,zt&=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 Ht=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Ht>>>26)|0,Ht&=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 Vt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Vt>>>26)|0,Vt&=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 Jt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Jt>>>26)|0,Jt&=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 Qt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Qt>>>26)|0,Qt&=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 Xt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Xt>>>26)|0,Xt&=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 Yt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Yt>>>26)|0,Yt&=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 $t=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+($t>>>26)|0,$t&=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 Gt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(Gt>>>26)|0,Gt&=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 jt=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(jt>>>26)|0,jt&=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 ti=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(ti>>>26)|0,ti&=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 ii=(u+o|0)+((i&8191)<<13)|0;u=(a+(i>>>13)|0)+(ii>>>26)|0,ii&=67108863,o=Math.imul(it,yt),i=Math.imul(it,xt),i=i+Math.imul(rt,yt)|0,a=Math.imul(rt,xt);var ri=(u+o|0)+((i&8191)<<13)|0;return u=(a+(i>>>13)|0)+(ri>>>26)|0,ri&=67108863,l[0]=Ft,l[1]=Kt,l[2]=Zt,l[3]=Nt,l[4]=Wt,l[5]=Ut,l[6]=zt,l[7]=Ht,l[8]=Vt,l[9]=Jt,l[10]=Qt,l[11]=Xt,l[12]=Yt,l[13]=$t,l[14]=Gt,l[15]=jt,l[16]=ti,l[17]=ii,l[18]=ri,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,y=v&67108863;l=l+(v/67108864|0)|0,y=y+u|0,u=y&67108863,l=l+(y>>>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,y=0;y<u;y++){var O=e[p+y],I=n[p+y],kt=e[p+y+u],F=n[p+y+u],Z=c*kt-v*F;F=c*F+v*kt,kt=Z,e[p+y]=O+kt,n[p+y]=I+F,e[p+y+u]=O-kt,n[p+y+u]=I-F,y!==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 y=0;y<n;y++){var O=o[y]*p[y]-i[y]*c[y];i[y]=o[y]*c[y]+i[y]*p[y],o[y]=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,y=1;(e.words[0]&y)===0&&v<26;++v,y<<=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 At(){R.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}g(At,R),At.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},At.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 Dt(){R.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}g(Dt,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 At;else if(t==="p224")r=new St;else if(t==="p192")r=new Dt;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):(x(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 y=c,O=0;y.cmp(l)!==0;O++)y=y.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 Rt(t)};function Rt(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(Rt,C),Rt.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},Rt.prototype.convertFrom=function(t){var r=this.imod(t.mul(this.rinv));return r.red=null,r},Rt.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)},Rt.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)},Rt.prototype.invm=function(t){var r=this.imod(t._invmp(this.m).mul(this.r2));return r._forceRed(this)}})(typeof ei>"u"||ei,Oi)});import{AggregatorClient as Ti,Env as Tt}from"@cetusprotocol/aggregator-sdk";import{SuiClient as Ii}from"@mysten/sui/client";import{normalizeSuiAddress as Fi}from"@mysten/sui/utils";import{CetusDlmmSDK as tr}from"@cetusprotocol/dlmm-sdk";import{SdkWrapper as ir}from"@cetusprotocol/common-sdk";import{FullRpcUrlMainnet as Ji,GraphRpcUrlMainnet as Qi}from"@cetusprotocol/common-sdk";var Ri={env:"mainnet",full_rpc_url:Ji,graph_rpc_url:Qi,aggregator_url:"https://api-sui.cetus.zone/router_v3",providers:[]};import{FullRpcUrlTestnet as Xi,GraphRpcUrlTestnet as Yi}from"@cetusprotocol/common-sdk";var Bi={env:"testnet",full_rpc_url:Xi,graph_rpc_url:Yi,aggregator_url:"https://api-sui.devcetus.com/router_v3",providers:["CETUS","DEEPBOOK","KRIYA","KRIYAV3","FLOWX","FLOWXV3","AFTERMATH","TURBOS","HAEDAL","VOLO","AFSUI"]};var Pi=Di(ni());import{Transaction as Ei}from"@mysten/sui/transactions";import{CoinAssist as si,d as A,DETAILS_KEYS as Ot}from"@cetusprotocol/common-sdk";import{BaseError as $i}from"@cetusprotocol/common-sdk";var ki=(_=>(_.UnsupportedDepositMode="UnsupportedDepositMode",_.PositionIdUndefined="PositionIdUndefined",_.ParameterError="ParameterError",_.ReachMaxIterations="ReachMaxIterations",_.BestLiquidityIsZero="BestLiquidityIsZero",_.SwapAmountError="SwapAmountError",_.AggregatorError="AggregatorError",_))(ki||{}),Et=class extends $i{constructor(m,d,g){super(m,d||"UnknownError",g)}static isZapErrorCode(m,d){return this.isErrorCode(m,d)}},qi=(b,m,d)=>{throw new Et(m.message,b,d)},Ct=(b,m,d)=>{throw new Et(m,b,d)};var oi=.005;var Lt=Di(ni());import{ClmmPoolUtil as Gi,d as Bt,TickMath as ji}from"@cetusprotocol/common-sdk";function Ci(b,m,d,g,f,S,M){let _=M?new Lt.default(b):new Lt.default(m),w=Gi.estLiquidityAndCoinAmountFromOneAmounts(g,f,_,M,!0,S,new Lt.default(d)),x=M?_.toString():w.coin_amount_a.toString(),D=M?w.coin_amount_b.toString():_.toString(),B=Bt(b).sub(x),K=Bt(m).sub(D);return{is_enough_amount:M?K.gte(0):B.gte(0),use_amount_a:x,use_amount_b:D,liquidity:w.liquidity_amount,amount_limit_a:w.coin_amount_limit_a,amount_limit_b:w.coin_amount_limit_b,remain_amount:M?K:B}}function mr(b,m,d,g,f,S,M){let _=ji.sqrtPriceX64ToTickIndex(new Lt.default(d)),w=M;_<g?w=!0:_>f&&(w=!1);let x=Ci(b,m,d,g,f,S,w);return x.is_enough_amount||(w=!w,x=Ci(b,m,d,g,f,S,w)),{fix_liquidity_amount_a:w,...x}}function Li(b,m,d,g){let f=Bt(b),S=Bt(d),M=Bt(g),_=f,w=m?f:Bt(0),x=m?Bt(0):f,D=M,B=Bt(M).mul(.999),K=Bt(0),k=_,E=null;function W(P){if(m){let L=w.minus(P),q=x.plus(P.mul(S));return{A:L,B:q,R:q.div(L)}}else{let L=w.plus(P.mul(S)),q=x.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,Bt(B).eq(0))break;k=L}}if(!E)return{swap_amount:"0",final_amount_a:w.toFixed(0),final_amount_b:x.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)}}import{BinUtils as ai}from"@cetusprotocol/dlmm-sdk";var 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:S,pool_id:M,active_id:_,lower_bin_id:w,upper_bin_id:x,active_bin_of_pool:D,strategy_type:B}=m,K=await this._sdk.DlmmSDK.Pool.getPool(M,!1),k,E=g,W=f;return _>x?(E=!1,g?(k=await this.findRouters(K.coin_type_a,K.coin_type_b,f),W=A(k.swap_out_amount).mul(1-.001).toFixed(0)):W=f):_<w&&(E=!0,g?W=f:(k=await this.findRouters(K.coin_type_b,K.coin_type_a,f),W=A(k.swap_out_amount).mul(1-.001).toFixed(0))),{liquidity_info:await this._sdk.DlmmSDK.Position.calculateAddLiquidityInfo({pool_id:M,coin_amount:W,fix_amount_a:E,active_id:_,bin_step:S,lower_bin_id:w,upper_bin_id:x,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:S,pool_id:M,active_id:_,lower_bin_id:w,upper_bin_id:x,active_bin_of_pool:D,strategy_type:B}=m;if(_>x||_<w)return this.calculateBalanceSwapAmountWithoutActiveId(m,d);let K=await this._sdk.DlmmSDK.Position.calculateAddLiquidityInfo({pool_id:M,coin_amount:f,fix_amount_a:g,active_id:_,bin_step:S,lower_bin_id:w,upper_bin_id:x,active_bin_of_pool:D,strategy_type:B}),{amount_a:k,amount_b:E}=K,W=g?A(E).div(k):A(k).div(E),bt=g?ai.getPricePerLamportFromBinId(_,S):A(1).div(ai.getPricePerLamportFromBinId(_,S)).toString(),N=await this._sdk.DlmmSDK.Pool.getPool(M,!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=A(t.swap_out_amount).div(t.swap_in_amount).toString())}catch{}let{swap_amount:P,final_amount_a:L,final_amount_b:q}=Li(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,At,St,Dt=0,qt=.02,C,Rt,h;do{let t=A(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=A(St.swap_out_amount).toFixed(0),e=await this._sdk.DlmmSDK.Position.calculateAddLiquidityInfo({pool_id:M,coin_amount:t,fix_amount_a:g,active_id:_,bin_step:S,lower_bin_id:w,upper_bin_id:x,active_bin_of_pool:D,strategy_type:B}),{amount_a:n,amount_b:s}=e,l=g?s:n,u=A(r).sub(l).div(r);if(u.gt(0)&&(h===void 0||u.lt(h))&&(C=St,Rt=e,h=u),A(r).gt(l))if(A(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:Dt}),T=A(T).mul(1-.01).toFixed(0),Dt++;else{R=St,At=e;break}else T=A(T).mul(1+.01).toFixed(0),T=Math.min(Number(A(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:Dt}),Dt++;if(Dt>5)break}while(!R&&A(T).gt(0));if(R===void 0&&C&&(R=C,At=Rt),R===void 0&&St){let{swap_out_amount:t}=St,r=await this._sdk.DlmmSDK.Position.calculateAddLiquidityInfo({pool_id:M,coin_amount:A(t).sub(1-.001).toFixed(0),fix_amount_a:!g,active_id:_,bin_step:S,lower_bin_id:w,upper_bin_id:x,active_bin_of_pool:D,strategy_type:B});R=St,At=r}return{swap_result:R,liquidity_info:At}}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:S,swap_result:M}=await this.calculateBalanceSwapAmount(m,d);return S===void 0?Ct("SwapAmountError","Best liquidity info is undefined",{[Ot.METHOD_NAME]:"preCalculateDepositAmount"}):{bin_infos:S,swap_result:M,fix_amount_a:g,coin_amount:f}}async buildDepositPayload(m,d){let{swap_slippage:g=oi,bin_step:f,pool_id:S,active_id:M,lower_bin_id:_,upper_bin_id:w,strategy_type:x,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 Ei;let N=await this._sdk.DlmmSDK.Pool.getPool(S,!1),{coin_type_a:P,coin_type_b:L}=N,q,T;if(W){let R=k?P:L,{swap_in_amount:At,route_obj:St}=W,Dt=si.buildCoinWithBalance(BigInt(At),R,d),qt={router:St,slippage:g,txb:d,inputCoin:Dt},C=await this._sdk.AggregatorClient.fixableRouterSwapV3(qt);k?(q=si.buildCoinWithBalance(BigInt(bt.amount_a),P,d),T=C):(q=C,T=si.buildCoinWithBalance(BigInt(bt.amount_b),L,d))}if(K){let R={pool_id:S,bin_infos:bt,coin_type_a:P,coin_type_b:L,active_id:M,strategy_type:x,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:S,bin_infos:bt,coin_type_a:P,coin_type_b:L,lower_bin_id:_,upper_bin_id:w,active_id:M,strategy_type:x,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,S=this._sdk.AggregatorClient;if(A(g).lt(1))return Ct("SwapAmountError","Swap amount is less than the minimum precision",{[Ot.METHOD_NAME]:"findRouters"});try{let M={from:m,target:d,amount:new Pi.default(g),byAmountIn:!0,depth:3,providers:f},_=await S.findRouters(M);if(_?.error)return Ct("AggregatorError",`Aggregator findRouters error: ${_?.error}`,{[Ot.METHOD_NAME]:"findRouters",[Ot.REQUEST_PARAMS]:M});if(!_?.paths||_?.paths?.length===0)return Ct("AggregatorError","Aggregator findRouters error: no router",{[Ot.METHOD_NAME]:"findRouters",[Ot.REQUEST_PARAMS]:M});let w=_.amountIn.toString(),x=_.amountOut.toString();return{swap_in_amount:w,swap_out_amount:x,route_obj:_}}catch(M){return console.log("\u{1F680} ~ ZapModule ~ error:",JSON.stringify(M,null,2)),qi("AggregatorError",M,{[Ot.METHOD_NAME]:"swapInPools"})}}calculateZapOutAvailableAmount(m){let{is_receive_coin_a:d,mode:g,active_id:f,bin_step:S,remove_bin_range:M}=m,_=ai.getPricePerLamportFromBinId(f,S),w,x="0",D="0",B="0";M.forEach(E=>{E.bin_id===f&&(w=E),x=A(x).add(E.amount_a).toFixed(0),D=A(D).add(E.amount_b).toFixed(0)});let K=A(x).sub(w?.amount_a||"0").toFixed(0),k=A(D).sub(w?.amount_b||"0").toFixed(0);return g==="OnlyCoinA"?d?B=K:B=A(x).mul(_).toFixed(0):g==="OnlyCoinB"?(D=k,d?B=A(D).div(_).toFixed(0):B=D):g==="Both"&&(d?B=A(D).div(_).add(x).toFixed(0):B=A(x).mul(_).add(D).toFixed(0)),{available_amount:B,user_total_amount_a:x,user_total_amount_b:D,active_bin:w,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:S,mode:M,expected_receive_amount:_,active_id:w}=m,{available_amount:x,user_total_amount_a:D,user_total_amount_b:B,active_bin:K}=this.calculateZapOutAvailableAmount(m);if(A(x).lt(A(_)))return Ct("SwapAmountError",`Available amount is less than the expected receive amount: ${x} < ${_}`,{[Ot.METHOD_NAME]:"preCalculateWithdrawAmount",[Ot.REQUEST_PARAMS]:m});let k=A(_).div(x),E;if(M==="Both"){let P=A(D).gt(0),L=P?A(D).mul(k).toFixed(0):A(B).mul(k).toFixed(0);E=this._sdk.DlmmSDK.Position.calculateRemoveLiquidityInfo({bins:g,active_id:w,fix_amount_a:P,coin_amount:L})}else{let P=M==="OnlyCoinA"?A(D).mul(k).toFixed(0):A(B).mul(k).toFixed(0);E=this._sdk.DlmmSDK.Position.calculateRemoveLiquidityInfo({bins:g,active_id:w,is_only_a:M==="OnlyCoinA",coin_amount:P})}let{amount_a:W,amount_b:bt}=E,N;return d&&A(bt).gt(0)&&(N=await this.findRouters(S,f,bt)),!d&&A(W).gt(0)&&(N=await this.findRouters(f,S,W)),{remove_liquidity_info:E,swap_result:N,mode:M,is_receive_coin_a:d,expected_receive_amount:_,remove_percent:k.toString()}}async buildWithdrawPayload(m){let d=new Ei,{withdraw_obj:g,swap_slippage:f=oi,bin_step:S,pool_id:M,active_id:_,collect_fee:w,reward_coins:x,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:M,bin_infos:bt,coin_type_a:D,coin_type_b:B,position_id:K,slippage:k,active_id:_,reward_coins:x,collect_fee:w,bin_step:S,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,At={router:R,slippage:f,txb:d,inputCoin:P?T:q},St=await this._sdk.AggregatorClient.fixableRouterSwapV3(At);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 It=class b extends ir{constructor(m,d){super(m),this._zapModule=new Pt(this),this._dlmmSDK=d||tr.createSDK({env:m.env,full_rpc_url:m.full_rpc_url}),this._aggregatorClient=new Ti({signer:Fi("0x0"),client:m.sui_client||new Ii({url:m.full_rpc_url}),env:m.env==="testnet"?Tt.Testnet:Tt.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 Ti({signer:Fi("0x0"),client:new Ii({url:m}),env:this._sdkOptions.env==="testnet"?Tt.Testnet:Tt.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"?b.createCustomSDK({...Ri,...m},d):b.createCustomSDK({...Bi,...m},d)}static createCustomSDK(m,d){return new b(m,d)}};var Me=It;export{It as CetusDlmmZapSDK,Et as ZapError,ki as ZapErrorCode,Pt as ZapModule,Li as calcExactSwapAmount,Ci as calculateLiquidityAmountEnough,mr as calculateLiquidityAmountSide,Me as default,oi as defaultSwapSlippage,qi as handleError,Ct as handleMessageError,Ri as zapMainnet,Bi as zapTestnet};
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|