@cetusprotocol/dlmm-sdk 0.2.0 → 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/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var Vr=Object.create;var sr=Object.defineProperty;var Xr=Object.getOwnPropertyDescriptor;var Jr=Object.getOwnPropertyNames;var Yr=Object.getPrototypeOf,tn=Object.prototype.hasOwnProperty;var en=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(i,t)=>(typeof require<"u"?require:i)[t]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});var rn=(n,i)=>()=>(i||n((i={exports:{}}).exports,i),i.exports);var nn=(n,i,t,r)=>{if(i&&typeof i=="object"||typeof i=="function")for(let e of Jr(i))!tn.call(n,e)&&e!==t&&sr(n,e,{get:()=>i[e],enumerable:!(r=Xr(i,e))||r.enumerable});return n};var Mi=(n,i,t)=>(t=n!=null?Vr(Yr(n)):{},nn(i||!n||!n.__esModule?sr(t,"default",{value:n,enumerable:!0}):t,n));var ke=rn((lr,Pi)=>{"use strict";(function(n,i){"use strict";function t(v,o){if(!v)throw new Error(o||"Assertion failed")}function r(v,o){v.super_=o;var u=function(){};u.prototype=o.prototype,v.prototype=new u,v.prototype.constructor=v}function e(v,o,u){if(e.isBN(v))return v;this.negative=0,this.words=null,this.length=0,this.red=null,v!==null&&((o==="le"||o==="be")&&(u=o,o=10),this._init(v||0,o||10,u||"be"))}typeof n=="object"?n.exports=e:i.BN=e,e.BN=e,e.wordSize=26;var s;try{typeof window<"u"&&typeof window.Buffer<"u"?s=window.Buffer:s=en("buffer").Buffer}catch{}e.isBN=function(o){return o instanceof e?!0:o!==null&&typeof o=="object"&&o.constructor.wordSize===e.wordSize&&Array.isArray(o.words)},e.max=function(o,u){return o.cmp(u)>0?o:u},e.min=function(o,u){return o.cmp(u)<0?o:u},e.prototype._init=function(o,u,h){if(typeof o=="number")return this._initNumber(o,u,h);if(typeof o=="object")return this._initArray(o,u,h);u==="hex"&&(u=16),t(u===(u|0)&&u>=2&&u<=36),o=o.toString().replace(/\s+/g,"");var m=0;o[0]==="-"&&(m++,this.negative=1),m<o.length&&(u===16?this._parseHex(o,m,h):(this._parseBase(o,u,m),h==="le"&&this._initArray(this.toArray(),u,h)))},e.prototype._initNumber=function(o,u,h){o<0&&(this.negative=1,o=-o),o<67108864?(this.words=[o&67108863],this.length=1):o<4503599627370496?(this.words=[o&67108863,o/67108864&67108863],this.length=2):(t(o<9007199254740992),this.words=[o&67108863,o/67108864&67108863,1],this.length=3),h==="le"&&this._initArray(this.toArray(),u,h)},e.prototype._initArray=function(o,u,h){if(t(typeof o.length=="number"),o.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(o.length/3),this.words=new Array(this.length);for(var m=0;m<this.length;m++)this.words[m]=0;var b,M,A=0;if(h==="be")for(m=o.length-1,b=0;m>=0;m-=3)M=o[m]|o[m-1]<<8|o[m-2]<<16,this.words[b]|=M<<A&67108863,this.words[b+1]=M>>>26-A&67108863,A+=24,A>=26&&(A-=26,b++);else if(h==="le")for(m=0,b=0;m<o.length;m+=3)M=o[m]|o[m+1]<<8|o[m+2]<<16,this.words[b]|=M<<A&67108863,this.words[b+1]=M>>>26-A&67108863,A+=24,A>=26&&(A-=26,b++);return this._strip()};function l(v,o){var u=v.charCodeAt(o);if(u>=48&&u<=57)return u-48;if(u>=65&&u<=70)return u-55;if(u>=97&&u<=102)return u-87;t(!1,"Invalid character in "+v)}function d(v,o,u){var h=l(v,u);return u-1>=o&&(h|=l(v,u-1)<<4),h}e.prototype._parseHex=function(o,u,h){this.length=Math.ceil((o.length-u)/6),this.words=new Array(this.length);for(var m=0;m<this.length;m++)this.words[m]=0;var b=0,M=0,A;if(h==="be")for(m=o.length-1;m>=u;m-=2)A=d(o,u,m)<<b,this.words[M]|=A&67108863,b>=18?(b-=18,M+=1,this.words[M]|=A>>>26):b+=8;else{var g=o.length-u;for(m=g%2===0?u+1:u;m<o.length;m+=2)A=d(o,u,m)<<b,this.words[M]|=A&67108863,b>=18?(b-=18,M+=1,this.words[M]|=A>>>26):b+=8}this._strip()};function f(v,o,u,h){for(var m=0,b=0,M=Math.min(v.length,u),A=o;A<M;A++){var g=v.charCodeAt(A)-48;m*=h,g>=49?b=g-49+10:g>=17?b=g-17+10:b=g,t(g>=0&&b<h,"Invalid character"),m+=b}return m}e.prototype._parseBase=function(o,u,h){this.words=[0],this.length=1;for(var m=0,b=1;b<=67108863;b*=u)m++;m--,b=b/u|0;for(var M=o.length-h,A=M%m,g=Math.min(M,M-A)+h,a=0,w=h;w<g;w+=m)a=f(o,w,w+m,u),this.imuln(b),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a);if(A!==0){var R=1;for(a=f(o,w,o.length,u),w=0;w<A;w++)R*=u;this.imuln(R),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a)}this._strip()},e.prototype.copy=function(o){o.words=new Array(this.length);for(var u=0;u<this.length;u++)o.words[u]=this.words[u];o.length=this.length,o.negative=this.negative,o.red=this.red};function c(v,o){v.words=o.words,v.length=o.length,v.negative=o.negative,v.red=o.red}if(e.prototype._move=function(o){c(o,this)},e.prototype.clone=function(){var o=new e(null);return this.copy(o),o},e.prototype._expand=function(o){for(;this.length<o;)this.words[this.length++]=0;return this},e.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},e.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{e.prototype[Symbol.for("nodejs.util.inspect.custom")]=p}catch{e.prototype.inspect=p}else e.prototype.inspect=p;function p(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var _=["","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"],y=[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],P=[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];e.prototype.toString=function(o,u){o=o||10,u=u|0||1;var h;if(o===16||o==="hex"){h="";for(var m=0,b=0,M=0;M<this.length;M++){var A=this.words[M],g=((A<<m|b)&16777215).toString(16);b=A>>>24-m&16777215,m+=2,m>=26&&(m-=26,M--),b!==0||M!==this.length-1?h=_[6-g.length]+g+h:h=g+h}for(b!==0&&(h=b.toString(16)+h);h.length%u!==0;)h="0"+h;return this.negative!==0&&(h="-"+h),h}if(o===(o|0)&&o>=2&&o<=36){var a=y[o],w=P[o];h="";var R=this.clone();for(R.negative=0;!R.isZero();){var D=R.modrn(w).toString(o);R=R.idivn(w),R.isZero()?h=D+h:h=_[a-D.length]+D+h}for(this.isZero()&&(h="0"+h);h.length%u!==0;)h="0"+h;return this.negative!==0&&(h="-"+h),h}t(!1,"Base should be between 2 and 36")},e.prototype.toNumber=function(){var o=this.words[0];return this.length===2?o+=this.words[1]*67108864:this.length===3&&this.words[2]===1?o+=4503599627370496+this.words[1]*67108864:this.length>2&&t(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-o:o},e.prototype.toJSON=function(){return this.toString(16,2)},s&&(e.prototype.toBuffer=function(o,u){return this.toArrayLike(s,o,u)}),e.prototype.toArray=function(o,u){return this.toArrayLike(Array,o,u)};var B=function(o,u){return o.allocUnsafe?o.allocUnsafe(u):new o(u)};e.prototype.toArrayLike=function(o,u,h){this._strip();var m=this.byteLength(),b=h||Math.max(1,m);t(m<=b,"byte array longer than desired length"),t(b>0,"Requested array length <= 0");var M=B(o,b),A=u==="le"?"LE":"BE";return this["_toArrayLike"+A](M,m),M},e.prototype._toArrayLikeLE=function(o,u){for(var h=0,m=0,b=0,M=0;b<this.length;b++){var A=this.words[b]<<M|m;o[h++]=A&255,h<o.length&&(o[h++]=A>>8&255),h<o.length&&(o[h++]=A>>16&255),M===6?(h<o.length&&(o[h++]=A>>24&255),m=0,M=0):(m=A>>>24,M+=2)}if(h<o.length)for(o[h++]=m;h<o.length;)o[h++]=0},e.prototype._toArrayLikeBE=function(o,u){for(var h=o.length-1,m=0,b=0,M=0;b<this.length;b++){var A=this.words[b]<<M|m;o[h--]=A&255,h>=0&&(o[h--]=A>>8&255),h>=0&&(o[h--]=A>>16&255),M===6?(h>=0&&(o[h--]=A>>24&255),m=0,M=0):(m=A>>>24,M+=2)}if(h>=0)for(o[h--]=m;h>=0;)o[h--]=0},Math.clz32?e.prototype._countBits=function(o){return 32-Math.clz32(o)}:e.prototype._countBits=function(o){var u=o,h=0;return u>=4096&&(h+=13,u>>>=13),u>=64&&(h+=7,u>>>=7),u>=8&&(h+=4,u>>>=4),u>=2&&(h+=2,u>>>=2),h+u},e.prototype._zeroBits=function(o){if(o===0)return 26;var u=o,h=0;return(u&8191)===0&&(h+=13,u>>>=13),(u&127)===0&&(h+=7,u>>>=7),(u&15)===0&&(h+=4,u>>>=4),(u&3)===0&&(h+=2,u>>>=2),(u&1)===0&&h++,h},e.prototype.bitLength=function(){var o=this.words[this.length-1],u=this._countBits(o);return(this.length-1)*26+u};function S(v){for(var o=new Array(v.bitLength()),u=0;u<o.length;u++){var h=u/26|0,m=u%26;o[u]=v.words[h]>>>m&1}return o}e.prototype.zeroBits=function(){if(this.isZero())return 0;for(var o=0,u=0;u<this.length;u++){var h=this._zeroBits(this.words[u]);if(o+=h,h!==26)break}return o},e.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},e.prototype.toTwos=function(o){return this.negative!==0?this.abs().inotn(o).iaddn(1):this.clone()},e.prototype.fromTwos=function(o){return this.testn(o-1)?this.notn(o).iaddn(1).ineg():this.clone()},e.prototype.isNeg=function(){return this.negative!==0},e.prototype.neg=function(){return this.clone().ineg()},e.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},e.prototype.iuor=function(o){for(;this.length<o.length;)this.words[this.length++]=0;for(var u=0;u<o.length;u++)this.words[u]=this.words[u]|o.words[u];return this._strip()},e.prototype.ior=function(o){return t((this.negative|o.negative)===0),this.iuor(o)},e.prototype.or=function(o){return this.length>o.length?this.clone().ior(o):o.clone().ior(this)},e.prototype.uor=function(o){return this.length>o.length?this.clone().iuor(o):o.clone().iuor(this)},e.prototype.iuand=function(o){var u;this.length>o.length?u=o:u=this;for(var h=0;h<u.length;h++)this.words[h]=this.words[h]&o.words[h];return this.length=u.length,this._strip()},e.prototype.iand=function(o){return t((this.negative|o.negative)===0),this.iuand(o)},e.prototype.and=function(o){return this.length>o.length?this.clone().iand(o):o.clone().iand(this)},e.prototype.uand=function(o){return this.length>o.length?this.clone().iuand(o):o.clone().iuand(this)},e.prototype.iuxor=function(o){var u,h;this.length>o.length?(u=this,h=o):(u=o,h=this);for(var m=0;m<h.length;m++)this.words[m]=u.words[m]^h.words[m];if(this!==u)for(;m<u.length;m++)this.words[m]=u.words[m];return this.length=u.length,this._strip()},e.prototype.ixor=function(o){return t((this.negative|o.negative)===0),this.iuxor(o)},e.prototype.xor=function(o){return this.length>o.length?this.clone().ixor(o):o.clone().ixor(this)},e.prototype.uxor=function(o){return this.length>o.length?this.clone().iuxor(o):o.clone().iuxor(this)},e.prototype.inotn=function(o){t(typeof o=="number"&&o>=0);var u=Math.ceil(o/26)|0,h=o%26;this._expand(u),h>0&&u--;for(var m=0;m<u;m++)this.words[m]=~this.words[m]&67108863;return h>0&&(this.words[m]=~this.words[m]&67108863>>26-h),this._strip()},e.prototype.notn=function(o){return this.clone().inotn(o)},e.prototype.setn=function(o,u){t(typeof o=="number"&&o>=0);var h=o/26|0,m=o%26;return this._expand(h+1),u?this.words[h]=this.words[h]|1<<m:this.words[h]=this.words[h]&~(1<<m),this._strip()},e.prototype.iadd=function(o){var u;if(this.negative!==0&&o.negative===0)return this.negative=0,u=this.isub(o),this.negative^=1,this._normSign();if(this.negative===0&&o.negative!==0)return o.negative=0,u=this.isub(o),o.negative=1,u._normSign();var h,m;this.length>o.length?(h=this,m=o):(h=o,m=this);for(var b=0,M=0;M<m.length;M++)u=(h.words[M]|0)+(m.words[M]|0)+b,this.words[M]=u&67108863,b=u>>>26;for(;b!==0&&M<h.length;M++)u=(h.words[M]|0)+b,this.words[M]=u&67108863,b=u>>>26;if(this.length=h.length,b!==0)this.words[this.length]=b,this.length++;else if(h!==this)for(;M<h.length;M++)this.words[M]=h.words[M];return this},e.prototype.add=function(o){var u;return o.negative!==0&&this.negative===0?(o.negative=0,u=this.sub(o),o.negative^=1,u):o.negative===0&&this.negative!==0?(this.negative=0,u=o.sub(this),this.negative=1,u):this.length>o.length?this.clone().iadd(o):o.clone().iadd(this)},e.prototype.isub=function(o){if(o.negative!==0){o.negative=0;var u=this.iadd(o);return o.negative=1,u._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(o),this.negative=1,this._normSign();var h=this.cmp(o);if(h===0)return this.negative=0,this.length=1,this.words[0]=0,this;var m,b;h>0?(m=this,b=o):(m=o,b=this);for(var M=0,A=0;A<b.length;A++)u=(m.words[A]|0)-(b.words[A]|0)+M,M=u>>26,this.words[A]=u&67108863;for(;M!==0&&A<m.length;A++)u=(m.words[A]|0)+M,M=u>>26,this.words[A]=u&67108863;if(M===0&&A<m.length&&m!==this)for(;A<m.length;A++)this.words[A]=m.words[A];return this.length=Math.max(this.length,A),m!==this&&(this.negative=1),this._strip()},e.prototype.sub=function(o){return this.clone().isub(o)};function T(v,o,u){u.negative=o.negative^v.negative;var h=v.length+o.length|0;u.length=h,h=h-1|0;var m=v.words[0]|0,b=o.words[0]|0,M=m*b,A=M&67108863,g=M/67108864|0;u.words[0]=A;for(var a=1;a<h;a++){for(var w=g>>>26,R=g&67108863,D=Math.min(a,o.length-1),Z=Math.max(0,a-v.length+1);Z<=D;Z++){var z=a-Z|0;m=v.words[z]|0,b=o.words[Z]|0,M=m*b+R,w+=M/67108864|0,R=M&67108863}u.words[a]=R|0,g=w|0}return g!==0?u.words[a]=g|0:u.length--,u._strip()}var C=function(o,u,h){var m=o.words,b=u.words,M=h.words,A=0,g,a,w,R=m[0]|0,D=R&8191,Z=R>>>13,z=m[1]|0,J=z&8191,N=z>>>13,et=m[2]|0,H=et&8191,Y=et>>>13,Se=m[3]|0,ut=Se&8191,dt=Se>>>13,Hi=m[4]|0,ft=Hi&8191,ct=Hi>>>13,Qi=m[5]|0,ht=Qi&8191,pt=Qi>>>13,Ki=m[6]|0,mt=Ki&8191,_t=Ki>>>13,$i=m[7]|0,gt=$i&8191,bt=$i>>>13,zi=m[8]|0,wt=zi&8191,vt=zi>>>13,Gi=m[9]|0,yt=Gi&8191,Mt=Gi>>>13,Vi=b[0]|0,Pt=Vi&8191,At=Vi>>>13,Xi=b[1]|0,Bt=Xi&8191,St=Xi>>>13,Ji=b[2]|0,It=Ji&8191,Et=Ji>>>13,Yi=b[3]|0,Ot=Yi&8191,xt=Yi>>>13,tr=b[4]|0,Tt=tr&8191,Ct=tr>>>13,er=b[5]|0,kt=er&8191,Rt=er>>>13,ir=b[6]|0,Dt=ir&8191,Ft=ir>>>13,rr=b[7]|0,Nt=rr&8191,qt=rr>>>13,nr=b[8]|0,Lt=nr&8191,jt=nr>>>13,or=b[9]|0,Wt=or&8191,Zt=or>>>13;h.negative=o.negative^u.negative,h.length=19,g=Math.imul(D,Pt),a=Math.imul(D,At),a=a+Math.imul(Z,Pt)|0,w=Math.imul(Z,At);var ri=(A+g|0)+((a&8191)<<13)|0;A=(w+(a>>>13)|0)+(ri>>>26)|0,ri&=67108863,g=Math.imul(J,Pt),a=Math.imul(J,At),a=a+Math.imul(N,Pt)|0,w=Math.imul(N,At),g=g+Math.imul(D,Bt)|0,a=a+Math.imul(D,St)|0,a=a+Math.imul(Z,Bt)|0,w=w+Math.imul(Z,St)|0;var ni=(A+g|0)+((a&8191)<<13)|0;A=(w+(a>>>13)|0)+(ni>>>26)|0,ni&=67108863,g=Math.imul(H,Pt),a=Math.imul(H,At),a=a+Math.imul(Y,Pt)|0,w=Math.imul(Y,At),g=g+Math.imul(J,Bt)|0,a=a+Math.imul(J,St)|0,a=a+Math.imul(N,Bt)|0,w=w+Math.imul(N,St)|0,g=g+Math.imul(D,It)|0,a=a+Math.imul(D,Et)|0,a=a+Math.imul(Z,It)|0,w=w+Math.imul(Z,Et)|0;var oi=(A+g|0)+((a&8191)<<13)|0;A=(w+(a>>>13)|0)+(oi>>>26)|0,oi&=67108863,g=Math.imul(ut,Pt),a=Math.imul(ut,At),a=a+Math.imul(dt,Pt)|0,w=Math.imul(dt,At),g=g+Math.imul(H,Bt)|0,a=a+Math.imul(H,St)|0,a=a+Math.imul(Y,Bt)|0,w=w+Math.imul(Y,St)|0,g=g+Math.imul(J,It)|0,a=a+Math.imul(J,Et)|0,a=a+Math.imul(N,It)|0,w=w+Math.imul(N,Et)|0,g=g+Math.imul(D,Ot)|0,a=a+Math.imul(D,xt)|0,a=a+Math.imul(Z,Ot)|0,w=w+Math.imul(Z,xt)|0;var si=(A+g|0)+((a&8191)<<13)|0;A=(w+(a>>>13)|0)+(si>>>26)|0,si&=67108863,g=Math.imul(ft,Pt),a=Math.imul(ft,At),a=a+Math.imul(ct,Pt)|0,w=Math.imul(ct,At),g=g+Math.imul(ut,Bt)|0,a=a+Math.imul(ut,St)|0,a=a+Math.imul(dt,Bt)|0,w=w+Math.imul(dt,St)|0,g=g+Math.imul(H,It)|0,a=a+Math.imul(H,Et)|0,a=a+Math.imul(Y,It)|0,w=w+Math.imul(Y,Et)|0,g=g+Math.imul(J,Ot)|0,a=a+Math.imul(J,xt)|0,a=a+Math.imul(N,Ot)|0,w=w+Math.imul(N,xt)|0,g=g+Math.imul(D,Tt)|0,a=a+Math.imul(D,Ct)|0,a=a+Math.imul(Z,Tt)|0,w=w+Math.imul(Z,Ct)|0;var ai=(A+g|0)+((a&8191)<<13)|0;A=(w+(a>>>13)|0)+(ai>>>26)|0,ai&=67108863,g=Math.imul(ht,Pt),a=Math.imul(ht,At),a=a+Math.imul(pt,Pt)|0,w=Math.imul(pt,At),g=g+Math.imul(ft,Bt)|0,a=a+Math.imul(ft,St)|0,a=a+Math.imul(ct,Bt)|0,w=w+Math.imul(ct,St)|0,g=g+Math.imul(ut,It)|0,a=a+Math.imul(ut,Et)|0,a=a+Math.imul(dt,It)|0,w=w+Math.imul(dt,Et)|0,g=g+Math.imul(H,Ot)|0,a=a+Math.imul(H,xt)|0,a=a+Math.imul(Y,Ot)|0,w=w+Math.imul(Y,xt)|0,g=g+Math.imul(J,Tt)|0,a=a+Math.imul(J,Ct)|0,a=a+Math.imul(N,Tt)|0,w=w+Math.imul(N,Ct)|0,g=g+Math.imul(D,kt)|0,a=a+Math.imul(D,Rt)|0,a=a+Math.imul(Z,kt)|0,w=w+Math.imul(Z,Rt)|0;var li=(A+g|0)+((a&8191)<<13)|0;A=(w+(a>>>13)|0)+(li>>>26)|0,li&=67108863,g=Math.imul(mt,Pt),a=Math.imul(mt,At),a=a+Math.imul(_t,Pt)|0,w=Math.imul(_t,At),g=g+Math.imul(ht,Bt)|0,a=a+Math.imul(ht,St)|0,a=a+Math.imul(pt,Bt)|0,w=w+Math.imul(pt,St)|0,g=g+Math.imul(ft,It)|0,a=a+Math.imul(ft,Et)|0,a=a+Math.imul(ct,It)|0,w=w+Math.imul(ct,Et)|0,g=g+Math.imul(ut,Ot)|0,a=a+Math.imul(ut,xt)|0,a=a+Math.imul(dt,Ot)|0,w=w+Math.imul(dt,xt)|0,g=g+Math.imul(H,Tt)|0,a=a+Math.imul(H,Ct)|0,a=a+Math.imul(Y,Tt)|0,w=w+Math.imul(Y,Ct)|0,g=g+Math.imul(J,kt)|0,a=a+Math.imul(J,Rt)|0,a=a+Math.imul(N,kt)|0,w=w+Math.imul(N,Rt)|0,g=g+Math.imul(D,Dt)|0,a=a+Math.imul(D,Ft)|0,a=a+Math.imul(Z,Dt)|0,w=w+Math.imul(Z,Ft)|0;var ui=(A+g|0)+((a&8191)<<13)|0;A=(w+(a>>>13)|0)+(ui>>>26)|0,ui&=67108863,g=Math.imul(gt,Pt),a=Math.imul(gt,At),a=a+Math.imul(bt,Pt)|0,w=Math.imul(bt,At),g=g+Math.imul(mt,Bt)|0,a=a+Math.imul(mt,St)|0,a=a+Math.imul(_t,Bt)|0,w=w+Math.imul(_t,St)|0,g=g+Math.imul(ht,It)|0,a=a+Math.imul(ht,Et)|0,a=a+Math.imul(pt,It)|0,w=w+Math.imul(pt,Et)|0,g=g+Math.imul(ft,Ot)|0,a=a+Math.imul(ft,xt)|0,a=a+Math.imul(ct,Ot)|0,w=w+Math.imul(ct,xt)|0,g=g+Math.imul(ut,Tt)|0,a=a+Math.imul(ut,Ct)|0,a=a+Math.imul(dt,Tt)|0,w=w+Math.imul(dt,Ct)|0,g=g+Math.imul(H,kt)|0,a=a+Math.imul(H,Rt)|0,a=a+Math.imul(Y,kt)|0,w=w+Math.imul(Y,Rt)|0,g=g+Math.imul(J,Dt)|0,a=a+Math.imul(J,Ft)|0,a=a+Math.imul(N,Dt)|0,w=w+Math.imul(N,Ft)|0,g=g+Math.imul(D,Nt)|0,a=a+Math.imul(D,qt)|0,a=a+Math.imul(Z,Nt)|0,w=w+Math.imul(Z,qt)|0;var di=(A+g|0)+((a&8191)<<13)|0;A=(w+(a>>>13)|0)+(di>>>26)|0,di&=67108863,g=Math.imul(wt,Pt),a=Math.imul(wt,At),a=a+Math.imul(vt,Pt)|0,w=Math.imul(vt,At),g=g+Math.imul(gt,Bt)|0,a=a+Math.imul(gt,St)|0,a=a+Math.imul(bt,Bt)|0,w=w+Math.imul(bt,St)|0,g=g+Math.imul(mt,It)|0,a=a+Math.imul(mt,Et)|0,a=a+Math.imul(_t,It)|0,w=w+Math.imul(_t,Et)|0,g=g+Math.imul(ht,Ot)|0,a=a+Math.imul(ht,xt)|0,a=a+Math.imul(pt,Ot)|0,w=w+Math.imul(pt,xt)|0,g=g+Math.imul(ft,Tt)|0,a=a+Math.imul(ft,Ct)|0,a=a+Math.imul(ct,Tt)|0,w=w+Math.imul(ct,Ct)|0,g=g+Math.imul(ut,kt)|0,a=a+Math.imul(ut,Rt)|0,a=a+Math.imul(dt,kt)|0,w=w+Math.imul(dt,Rt)|0,g=g+Math.imul(H,Dt)|0,a=a+Math.imul(H,Ft)|0,a=a+Math.imul(Y,Dt)|0,w=w+Math.imul(Y,Ft)|0,g=g+Math.imul(J,Nt)|0,a=a+Math.imul(J,qt)|0,a=a+Math.imul(N,Nt)|0,w=w+Math.imul(N,qt)|0,g=g+Math.imul(D,Lt)|0,a=a+Math.imul(D,jt)|0,a=a+Math.imul(Z,Lt)|0,w=w+Math.imul(Z,jt)|0;var fi=(A+g|0)+((a&8191)<<13)|0;A=(w+(a>>>13)|0)+(fi>>>26)|0,fi&=67108863,g=Math.imul(yt,Pt),a=Math.imul(yt,At),a=a+Math.imul(Mt,Pt)|0,w=Math.imul(Mt,At),g=g+Math.imul(wt,Bt)|0,a=a+Math.imul(wt,St)|0,a=a+Math.imul(vt,Bt)|0,w=w+Math.imul(vt,St)|0,g=g+Math.imul(gt,It)|0,a=a+Math.imul(gt,Et)|0,a=a+Math.imul(bt,It)|0,w=w+Math.imul(bt,Et)|0,g=g+Math.imul(mt,Ot)|0,a=a+Math.imul(mt,xt)|0,a=a+Math.imul(_t,Ot)|0,w=w+Math.imul(_t,xt)|0,g=g+Math.imul(ht,Tt)|0,a=a+Math.imul(ht,Ct)|0,a=a+Math.imul(pt,Tt)|0,w=w+Math.imul(pt,Ct)|0,g=g+Math.imul(ft,kt)|0,a=a+Math.imul(ft,Rt)|0,a=a+Math.imul(ct,kt)|0,w=w+Math.imul(ct,Rt)|0,g=g+Math.imul(ut,Dt)|0,a=a+Math.imul(ut,Ft)|0,a=a+Math.imul(dt,Dt)|0,w=w+Math.imul(dt,Ft)|0,g=g+Math.imul(H,Nt)|0,a=a+Math.imul(H,qt)|0,a=a+Math.imul(Y,Nt)|0,w=w+Math.imul(Y,qt)|0,g=g+Math.imul(J,Lt)|0,a=a+Math.imul(J,jt)|0,a=a+Math.imul(N,Lt)|0,w=w+Math.imul(N,jt)|0,g=g+Math.imul(D,Wt)|0,a=a+Math.imul(D,Zt)|0,a=a+Math.imul(Z,Wt)|0,w=w+Math.imul(Z,Zt)|0;var ci=(A+g|0)+((a&8191)<<13)|0;A=(w+(a>>>13)|0)+(ci>>>26)|0,ci&=67108863,g=Math.imul(yt,Bt),a=Math.imul(yt,St),a=a+Math.imul(Mt,Bt)|0,w=Math.imul(Mt,St),g=g+Math.imul(wt,It)|0,a=a+Math.imul(wt,Et)|0,a=a+Math.imul(vt,It)|0,w=w+Math.imul(vt,Et)|0,g=g+Math.imul(gt,Ot)|0,a=a+Math.imul(gt,xt)|0,a=a+Math.imul(bt,Ot)|0,w=w+Math.imul(bt,xt)|0,g=g+Math.imul(mt,Tt)|0,a=a+Math.imul(mt,Ct)|0,a=a+Math.imul(_t,Tt)|0,w=w+Math.imul(_t,Ct)|0,g=g+Math.imul(ht,kt)|0,a=a+Math.imul(ht,Rt)|0,a=a+Math.imul(pt,kt)|0,w=w+Math.imul(pt,Rt)|0,g=g+Math.imul(ft,Dt)|0,a=a+Math.imul(ft,Ft)|0,a=a+Math.imul(ct,Dt)|0,w=w+Math.imul(ct,Ft)|0,g=g+Math.imul(ut,Nt)|0,a=a+Math.imul(ut,qt)|0,a=a+Math.imul(dt,Nt)|0,w=w+Math.imul(dt,qt)|0,g=g+Math.imul(H,Lt)|0,a=a+Math.imul(H,jt)|0,a=a+Math.imul(Y,Lt)|0,w=w+Math.imul(Y,jt)|0,g=g+Math.imul(J,Wt)|0,a=a+Math.imul(J,Zt)|0,a=a+Math.imul(N,Wt)|0,w=w+Math.imul(N,Zt)|0;var hi=(A+g|0)+((a&8191)<<13)|0;A=(w+(a>>>13)|0)+(hi>>>26)|0,hi&=67108863,g=Math.imul(yt,It),a=Math.imul(yt,Et),a=a+Math.imul(Mt,It)|0,w=Math.imul(Mt,Et),g=g+Math.imul(wt,Ot)|0,a=a+Math.imul(wt,xt)|0,a=a+Math.imul(vt,Ot)|0,w=w+Math.imul(vt,xt)|0,g=g+Math.imul(gt,Tt)|0,a=a+Math.imul(gt,Ct)|0,a=a+Math.imul(bt,Tt)|0,w=w+Math.imul(bt,Ct)|0,g=g+Math.imul(mt,kt)|0,a=a+Math.imul(mt,Rt)|0,a=a+Math.imul(_t,kt)|0,w=w+Math.imul(_t,Rt)|0,g=g+Math.imul(ht,Dt)|0,a=a+Math.imul(ht,Ft)|0,a=a+Math.imul(pt,Dt)|0,w=w+Math.imul(pt,Ft)|0,g=g+Math.imul(ft,Nt)|0,a=a+Math.imul(ft,qt)|0,a=a+Math.imul(ct,Nt)|0,w=w+Math.imul(ct,qt)|0,g=g+Math.imul(ut,Lt)|0,a=a+Math.imul(ut,jt)|0,a=a+Math.imul(dt,Lt)|0,w=w+Math.imul(dt,jt)|0,g=g+Math.imul(H,Wt)|0,a=a+Math.imul(H,Zt)|0,a=a+Math.imul(Y,Wt)|0,w=w+Math.imul(Y,Zt)|0;var pi=(A+g|0)+((a&8191)<<13)|0;A=(w+(a>>>13)|0)+(pi>>>26)|0,pi&=67108863,g=Math.imul(yt,Ot),a=Math.imul(yt,xt),a=a+Math.imul(Mt,Ot)|0,w=Math.imul(Mt,xt),g=g+Math.imul(wt,Tt)|0,a=a+Math.imul(wt,Ct)|0,a=a+Math.imul(vt,Tt)|0,w=w+Math.imul(vt,Ct)|0,g=g+Math.imul(gt,kt)|0,a=a+Math.imul(gt,Rt)|0,a=a+Math.imul(bt,kt)|0,w=w+Math.imul(bt,Rt)|0,g=g+Math.imul(mt,Dt)|0,a=a+Math.imul(mt,Ft)|0,a=a+Math.imul(_t,Dt)|0,w=w+Math.imul(_t,Ft)|0,g=g+Math.imul(ht,Nt)|0,a=a+Math.imul(ht,qt)|0,a=a+Math.imul(pt,Nt)|0,w=w+Math.imul(pt,qt)|0,g=g+Math.imul(ft,Lt)|0,a=a+Math.imul(ft,jt)|0,a=a+Math.imul(ct,Lt)|0,w=w+Math.imul(ct,jt)|0,g=g+Math.imul(ut,Wt)|0,a=a+Math.imul(ut,Zt)|0,a=a+Math.imul(dt,Wt)|0,w=w+Math.imul(dt,Zt)|0;var mi=(A+g|0)+((a&8191)<<13)|0;A=(w+(a>>>13)|0)+(mi>>>26)|0,mi&=67108863,g=Math.imul(yt,Tt),a=Math.imul(yt,Ct),a=a+Math.imul(Mt,Tt)|0,w=Math.imul(Mt,Ct),g=g+Math.imul(wt,kt)|0,a=a+Math.imul(wt,Rt)|0,a=a+Math.imul(vt,kt)|0,w=w+Math.imul(vt,Rt)|0,g=g+Math.imul(gt,Dt)|0,a=a+Math.imul(gt,Ft)|0,a=a+Math.imul(bt,Dt)|0,w=w+Math.imul(bt,Ft)|0,g=g+Math.imul(mt,Nt)|0,a=a+Math.imul(mt,qt)|0,a=a+Math.imul(_t,Nt)|0,w=w+Math.imul(_t,qt)|0,g=g+Math.imul(ht,Lt)|0,a=a+Math.imul(ht,jt)|0,a=a+Math.imul(pt,Lt)|0,w=w+Math.imul(pt,jt)|0,g=g+Math.imul(ft,Wt)|0,a=a+Math.imul(ft,Zt)|0,a=a+Math.imul(ct,Wt)|0,w=w+Math.imul(ct,Zt)|0;var _i=(A+g|0)+((a&8191)<<13)|0;A=(w+(a>>>13)|0)+(_i>>>26)|0,_i&=67108863,g=Math.imul(yt,kt),a=Math.imul(yt,Rt),a=a+Math.imul(Mt,kt)|0,w=Math.imul(Mt,Rt),g=g+Math.imul(wt,Dt)|0,a=a+Math.imul(wt,Ft)|0,a=a+Math.imul(vt,Dt)|0,w=w+Math.imul(vt,Ft)|0,g=g+Math.imul(gt,Nt)|0,a=a+Math.imul(gt,qt)|0,a=a+Math.imul(bt,Nt)|0,w=w+Math.imul(bt,qt)|0,g=g+Math.imul(mt,Lt)|0,a=a+Math.imul(mt,jt)|0,a=a+Math.imul(_t,Lt)|0,w=w+Math.imul(_t,jt)|0,g=g+Math.imul(ht,Wt)|0,a=a+Math.imul(ht,Zt)|0,a=a+Math.imul(pt,Wt)|0,w=w+Math.imul(pt,Zt)|0;var gi=(A+g|0)+((a&8191)<<13)|0;A=(w+(a>>>13)|0)+(gi>>>26)|0,gi&=67108863,g=Math.imul(yt,Dt),a=Math.imul(yt,Ft),a=a+Math.imul(Mt,Dt)|0,w=Math.imul(Mt,Ft),g=g+Math.imul(wt,Nt)|0,a=a+Math.imul(wt,qt)|0,a=a+Math.imul(vt,Nt)|0,w=w+Math.imul(vt,qt)|0,g=g+Math.imul(gt,Lt)|0,a=a+Math.imul(gt,jt)|0,a=a+Math.imul(bt,Lt)|0,w=w+Math.imul(bt,jt)|0,g=g+Math.imul(mt,Wt)|0,a=a+Math.imul(mt,Zt)|0,a=a+Math.imul(_t,Wt)|0,w=w+Math.imul(_t,Zt)|0;var bi=(A+g|0)+((a&8191)<<13)|0;A=(w+(a>>>13)|0)+(bi>>>26)|0,bi&=67108863,g=Math.imul(yt,Nt),a=Math.imul(yt,qt),a=a+Math.imul(Mt,Nt)|0,w=Math.imul(Mt,qt),g=g+Math.imul(wt,Lt)|0,a=a+Math.imul(wt,jt)|0,a=a+Math.imul(vt,Lt)|0,w=w+Math.imul(vt,jt)|0,g=g+Math.imul(gt,Wt)|0,a=a+Math.imul(gt,Zt)|0,a=a+Math.imul(bt,Wt)|0,w=w+Math.imul(bt,Zt)|0;var wi=(A+g|0)+((a&8191)<<13)|0;A=(w+(a>>>13)|0)+(wi>>>26)|0,wi&=67108863,g=Math.imul(yt,Lt),a=Math.imul(yt,jt),a=a+Math.imul(Mt,Lt)|0,w=Math.imul(Mt,jt),g=g+Math.imul(wt,Wt)|0,a=a+Math.imul(wt,Zt)|0,a=a+Math.imul(vt,Wt)|0,w=w+Math.imul(vt,Zt)|0;var vi=(A+g|0)+((a&8191)<<13)|0;A=(w+(a>>>13)|0)+(vi>>>26)|0,vi&=67108863,g=Math.imul(yt,Wt),a=Math.imul(yt,Zt),a=a+Math.imul(Mt,Wt)|0,w=Math.imul(Mt,Zt);var yi=(A+g|0)+((a&8191)<<13)|0;return A=(w+(a>>>13)|0)+(yi>>>26)|0,yi&=67108863,M[0]=ri,M[1]=ni,M[2]=oi,M[3]=si,M[4]=ai,M[5]=li,M[6]=ui,M[7]=di,M[8]=fi,M[9]=ci,M[10]=hi,M[11]=pi,M[12]=mi,M[13]=_i,M[14]=gi,M[15]=bi,M[16]=wi,M[17]=vi,M[18]=yi,A!==0&&(M[19]=A,h.length++),h};Math.imul||(C=T);function k(v,o,u){u.negative=o.negative^v.negative,u.length=v.length+o.length;for(var h=0,m=0,b=0;b<u.length-1;b++){var M=m;m=0;for(var A=h&67108863,g=Math.min(b,o.length-1),a=Math.max(0,b-v.length+1);a<=g;a++){var w=b-a,R=v.words[w]|0,D=o.words[a]|0,Z=R*D,z=Z&67108863;M=M+(Z/67108864|0)|0,z=z+A|0,A=z&67108863,M=M+(z>>>26)|0,m+=M>>>26,M&=67108863}u.words[b]=A,h=M,M=m}return h!==0?u.words[b]=h:u.length--,u._strip()}function O(v,o,u){return k(v,o,u)}e.prototype.mulTo=function(o,u){var h,m=this.length+o.length;return this.length===10&&o.length===10?h=C(this,o,u):m<63?h=T(this,o,u):m<1024?h=k(this,o,u):h=O(this,o,u),h};function x(v,o){this.x=v,this.y=o}x.prototype.makeRBT=function(o){for(var u=new Array(o),h=e.prototype._countBits(o)-1,m=0;m<o;m++)u[m]=this.revBin(m,h,o);return u},x.prototype.revBin=function(o,u,h){if(o===0||o===h-1)return o;for(var m=0,b=0;b<u;b++)m|=(o&1)<<u-b-1,o>>=1;return m},x.prototype.permute=function(o,u,h,m,b,M){for(var A=0;A<M;A++)m[A]=u[o[A]],b[A]=h[o[A]]},x.prototype.transform=function(o,u,h,m,b,M){this.permute(M,o,u,h,m,b);for(var A=1;A<b;A<<=1)for(var g=A<<1,a=Math.cos(2*Math.PI/g),w=Math.sin(2*Math.PI/g),R=0;R<b;R+=g)for(var D=a,Z=w,z=0;z<A;z++){var J=h[R+z],N=m[R+z],et=h[R+z+A],H=m[R+z+A],Y=D*et-Z*H;H=D*H+Z*et,et=Y,h[R+z]=J+et,m[R+z]=N+H,h[R+z+A]=J-et,m[R+z+A]=N-H,z!==g&&(Y=a*D-w*Z,Z=a*Z+w*D,D=Y)}},x.prototype.guessLen13b=function(o,u){var h=Math.max(u,o)|1,m=h&1,b=0;for(h=h/2|0;h;h=h>>>1)b++;return 1<<b+1+m},x.prototype.conjugate=function(o,u,h){if(!(h<=1))for(var m=0;m<h/2;m++){var b=o[m];o[m]=o[h-m-1],o[h-m-1]=b,b=u[m],u[m]=-u[h-m-1],u[h-m-1]=-b}},x.prototype.normalize13b=function(o,u){for(var h=0,m=0;m<u/2;m++){var b=Math.round(o[2*m+1]/u)*8192+Math.round(o[2*m]/u)+h;o[m]=b&67108863,b<67108864?h=0:h=b/67108864|0}return o},x.prototype.convert13b=function(o,u,h,m){for(var b=0,M=0;M<u;M++)b=b+(o[M]|0),h[2*M]=b&8191,b=b>>>13,h[2*M+1]=b&8191,b=b>>>13;for(M=2*u;M<m;++M)h[M]=0;t(b===0),t((b&-8192)===0)},x.prototype.stub=function(o){for(var u=new Array(o),h=0;h<o;h++)u[h]=0;return u},x.prototype.mulp=function(o,u,h){var m=2*this.guessLen13b(o.length,u.length),b=this.makeRBT(m),M=this.stub(m),A=new Array(m),g=new Array(m),a=new Array(m),w=new Array(m),R=new Array(m),D=new Array(m),Z=h.words;Z.length=m,this.convert13b(o.words,o.length,A,m),this.convert13b(u.words,u.length,w,m),this.transform(A,M,g,a,m,b),this.transform(w,M,R,D,m,b);for(var z=0;z<m;z++){var J=g[z]*R[z]-a[z]*D[z];a[z]=g[z]*D[z]+a[z]*R[z],g[z]=J}return this.conjugate(g,a,m),this.transform(g,a,Z,M,m,b),this.conjugate(Z,M,m),this.normalize13b(Z,m),h.negative=o.negative^u.negative,h.length=o.length+u.length,h._strip()},e.prototype.mul=function(o){var u=new e(null);return u.words=new Array(this.length+o.length),this.mulTo(o,u)},e.prototype.mulf=function(o){var u=new e(null);return u.words=new Array(this.length+o.length),O(this,o,u)},e.prototype.imul=function(o){return this.clone().mulTo(o,this)},e.prototype.imuln=function(o){var u=o<0;u&&(o=-o),t(typeof o=="number"),t(o<67108864);for(var h=0,m=0;m<this.length;m++){var b=(this.words[m]|0)*o,M=(b&67108863)+(h&67108863);h>>=26,h+=b/67108864|0,h+=M>>>26,this.words[m]=M&67108863}return h!==0&&(this.words[m]=h,this.length++),this.length=o===0?1:this.length,u?this.ineg():this},e.prototype.muln=function(o){return this.clone().imuln(o)},e.prototype.sqr=function(){return this.mul(this)},e.prototype.isqr=function(){return this.imul(this.clone())},e.prototype.pow=function(o){var u=S(o);if(u.length===0)return new e(1);for(var h=this,m=0;m<u.length&&u[m]===0;m++,h=h.sqr());if(++m<u.length)for(var b=h.sqr();m<u.length;m++,b=b.sqr())u[m]!==0&&(h=h.mul(b));return h},e.prototype.iushln=function(o){t(typeof o=="number"&&o>=0);var u=o%26,h=(o-u)/26,m=67108863>>>26-u<<26-u,b;if(u!==0){var M=0;for(b=0;b<this.length;b++){var A=this.words[b]&m,g=(this.words[b]|0)-A<<u;this.words[b]=g|M,M=A>>>26-u}M&&(this.words[b]=M,this.length++)}if(h!==0){for(b=this.length-1;b>=0;b--)this.words[b+h]=this.words[b];for(b=0;b<h;b++)this.words[b]=0;this.length+=h}return this._strip()},e.prototype.ishln=function(o){return t(this.negative===0),this.iushln(o)},e.prototype.iushrn=function(o,u,h){t(typeof o=="number"&&o>=0);var m;u?m=(u-u%26)/26:m=0;var b=o%26,M=Math.min((o-b)/26,this.length),A=67108863^67108863>>>b<<b,g=h;if(m-=M,m=Math.max(0,m),g){for(var a=0;a<M;a++)g.words[a]=this.words[a];g.length=M}if(M!==0)if(this.length>M)for(this.length-=M,a=0;a<this.length;a++)this.words[a]=this.words[a+M];else this.words[0]=0,this.length=1;var w=0;for(a=this.length-1;a>=0&&(w!==0||a>=m);a--){var R=this.words[a]|0;this.words[a]=w<<26-b|R>>>b,w=R&A}return g&&w!==0&&(g.words[g.length++]=w),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},e.prototype.ishrn=function(o,u,h){return t(this.negative===0),this.iushrn(o,u,h)},e.prototype.shln=function(o){return this.clone().ishln(o)},e.prototype.ushln=function(o){return this.clone().iushln(o)},e.prototype.shrn=function(o){return this.clone().ishrn(o)},e.prototype.ushrn=function(o){return this.clone().iushrn(o)},e.prototype.testn=function(o){t(typeof o=="number"&&o>=0);var u=o%26,h=(o-u)/26,m=1<<u;if(this.length<=h)return!1;var b=this.words[h];return!!(b&m)},e.prototype.imaskn=function(o){t(typeof o=="number"&&o>=0);var u=o%26,h=(o-u)/26;if(t(this.negative===0,"imaskn works only with positive numbers"),this.length<=h)return this;if(u!==0&&h++,this.length=Math.min(h,this.length),u!==0){var m=67108863^67108863>>>u<<u;this.words[this.length-1]&=m}return this._strip()},e.prototype.maskn=function(o){return this.clone().imaskn(o)},e.prototype.iaddn=function(o){return t(typeof o=="number"),t(o<67108864),o<0?this.isubn(-o):this.negative!==0?this.length===1&&(this.words[0]|0)<=o?(this.words[0]=o-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(o),this.negative=1,this):this._iaddn(o)},e.prototype._iaddn=function(o){this.words[0]+=o;for(var u=0;u<this.length&&this.words[u]>=67108864;u++)this.words[u]-=67108864,u===this.length-1?this.words[u+1]=1:this.words[u+1]++;return this.length=Math.max(this.length,u+1),this},e.prototype.isubn=function(o){if(t(typeof o=="number"),t(o<67108864),o<0)return this.iaddn(-o);if(this.negative!==0)return this.negative=0,this.iaddn(o),this.negative=1,this;if(this.words[0]-=o,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var u=0;u<this.length&&this.words[u]<0;u++)this.words[u]+=67108864,this.words[u+1]-=1;return this._strip()},e.prototype.addn=function(o){return this.clone().iaddn(o)},e.prototype.subn=function(o){return this.clone().isubn(o)},e.prototype.iabs=function(){return this.negative=0,this},e.prototype.abs=function(){return this.clone().iabs()},e.prototype._ishlnsubmul=function(o,u,h){var m=o.length+h,b;this._expand(m);var M,A=0;for(b=0;b<o.length;b++){M=(this.words[b+h]|0)+A;var g=(o.words[b]|0)*u;M-=g&67108863,A=(M>>26)-(g/67108864|0),this.words[b+h]=M&67108863}for(;b<this.length-h;b++)M=(this.words[b+h]|0)+A,A=M>>26,this.words[b+h]=M&67108863;if(A===0)return this._strip();for(t(A===-1),A=0,b=0;b<this.length;b++)M=-(this.words[b]|0)+A,A=M>>26,this.words[b]=M&67108863;return this.negative=1,this._strip()},e.prototype._wordDiv=function(o,u){var h=this.length-o.length,m=this.clone(),b=o,M=b.words[b.length-1]|0,A=this._countBits(M);h=26-A,h!==0&&(b=b.ushln(h),m.iushln(h),M=b.words[b.length-1]|0);var g=m.length-b.length,a;if(u!=="mod"){a=new e(null),a.length=g+1,a.words=new Array(a.length);for(var w=0;w<a.length;w++)a.words[w]=0}var R=m.clone()._ishlnsubmul(b,1,g);R.negative===0&&(m=R,a&&(a.words[g]=1));for(var D=g-1;D>=0;D--){var Z=(m.words[b.length+D]|0)*67108864+(m.words[b.length+D-1]|0);for(Z=Math.min(Z/M|0,67108863),m._ishlnsubmul(b,Z,D);m.negative!==0;)Z--,m.negative=0,m._ishlnsubmul(b,1,D),m.isZero()||(m.negative^=1);a&&(a.words[D]=Z)}return a&&a._strip(),m._strip(),u!=="div"&&h!==0&&m.iushrn(h),{div:a||null,mod:m}},e.prototype.divmod=function(o,u,h){if(t(!o.isZero()),this.isZero())return{div:new e(0),mod:new e(0)};var m,b,M;return this.negative!==0&&o.negative===0?(M=this.neg().divmod(o,u),u!=="mod"&&(m=M.div.neg()),u!=="div"&&(b=M.mod.neg(),h&&b.negative!==0&&b.iadd(o)),{div:m,mod:b}):this.negative===0&&o.negative!==0?(M=this.divmod(o.neg(),u),u!=="mod"&&(m=M.div.neg()),{div:m,mod:M.mod}):(this.negative&o.negative)!==0?(M=this.neg().divmod(o.neg(),u),u!=="div"&&(b=M.mod.neg(),h&&b.negative!==0&&b.isub(o)),{div:M.div,mod:b}):o.length>this.length||this.cmp(o)<0?{div:new e(0),mod:this}:o.length===1?u==="div"?{div:this.divn(o.words[0]),mod:null}:u==="mod"?{div:null,mod:new e(this.modrn(o.words[0]))}:{div:this.divn(o.words[0]),mod:new e(this.modrn(o.words[0]))}:this._wordDiv(o,u)},e.prototype.div=function(o){return this.divmod(o,"div",!1).div},e.prototype.mod=function(o){return this.divmod(o,"mod",!1).mod},e.prototype.umod=function(o){return this.divmod(o,"mod",!0).mod},e.prototype.divRound=function(o){var u=this.divmod(o);if(u.mod.isZero())return u.div;var h=u.div.negative!==0?u.mod.isub(o):u.mod,m=o.ushrn(1),b=o.andln(1),M=h.cmp(m);return M<0||b===1&&M===0?u.div:u.div.negative!==0?u.div.isubn(1):u.div.iaddn(1)},e.prototype.modrn=function(o){var u=o<0;u&&(o=-o),t(o<=67108863);for(var h=(1<<26)%o,m=0,b=this.length-1;b>=0;b--)m=(h*m+(this.words[b]|0))%o;return u?-m:m},e.prototype.modn=function(o){return this.modrn(o)},e.prototype.idivn=function(o){var u=o<0;u&&(o=-o),t(o<=67108863);for(var h=0,m=this.length-1;m>=0;m--){var b=(this.words[m]|0)+h*67108864;this.words[m]=b/o|0,h=b%o}return this._strip(),u?this.ineg():this},e.prototype.divn=function(o){return this.clone().idivn(o)},e.prototype.egcd=function(o){t(o.negative===0),t(!o.isZero());var u=this,h=o.clone();u.negative!==0?u=u.umod(o):u=u.clone();for(var m=new e(1),b=new e(0),M=new e(0),A=new e(1),g=0;u.isEven()&&h.isEven();)u.iushrn(1),h.iushrn(1),++g;for(var a=h.clone(),w=u.clone();!u.isZero();){for(var R=0,D=1;(u.words[0]&D)===0&&R<26;++R,D<<=1);if(R>0)for(u.iushrn(R);R-- >0;)(m.isOdd()||b.isOdd())&&(m.iadd(a),b.isub(w)),m.iushrn(1),b.iushrn(1);for(var Z=0,z=1;(h.words[0]&z)===0&&Z<26;++Z,z<<=1);if(Z>0)for(h.iushrn(Z);Z-- >0;)(M.isOdd()||A.isOdd())&&(M.iadd(a),A.isub(w)),M.iushrn(1),A.iushrn(1);u.cmp(h)>=0?(u.isub(h),m.isub(M),b.isub(A)):(h.isub(u),M.isub(m),A.isub(b))}return{a:M,b:A,gcd:h.iushln(g)}},e.prototype._invmp=function(o){t(o.negative===0),t(!o.isZero());var u=this,h=o.clone();u.negative!==0?u=u.umod(o):u=u.clone();for(var m=new e(1),b=new e(0),M=h.clone();u.cmpn(1)>0&&h.cmpn(1)>0;){for(var A=0,g=1;(u.words[0]&g)===0&&A<26;++A,g<<=1);if(A>0)for(u.iushrn(A);A-- >0;)m.isOdd()&&m.iadd(M),m.iushrn(1);for(var a=0,w=1;(h.words[0]&w)===0&&a<26;++a,w<<=1);if(a>0)for(h.iushrn(a);a-- >0;)b.isOdd()&&b.iadd(M),b.iushrn(1);u.cmp(h)>=0?(u.isub(h),m.isub(b)):(h.isub(u),b.isub(m))}var R;return u.cmpn(1)===0?R=m:R=b,R.cmpn(0)<0&&R.iadd(o),R},e.prototype.gcd=function(o){if(this.isZero())return o.abs();if(o.isZero())return this.abs();var u=this.clone(),h=o.clone();u.negative=0,h.negative=0;for(var m=0;u.isEven()&&h.isEven();m++)u.iushrn(1),h.iushrn(1);do{for(;u.isEven();)u.iushrn(1);for(;h.isEven();)h.iushrn(1);var b=u.cmp(h);if(b<0){var M=u;u=h,h=M}else if(b===0||h.cmpn(1)===0)break;u.isub(h)}while(!0);return h.iushln(m)},e.prototype.invm=function(o){return this.egcd(o).a.umod(o)},e.prototype.isEven=function(){return(this.words[0]&1)===0},e.prototype.isOdd=function(){return(this.words[0]&1)===1},e.prototype.andln=function(o){return this.words[0]&o},e.prototype.bincn=function(o){t(typeof o=="number");var u=o%26,h=(o-u)/26,m=1<<u;if(this.length<=h)return this._expand(h+1),this.words[h]|=m,this;for(var b=m,M=h;b!==0&&M<this.length;M++){var A=this.words[M]|0;A+=b,b=A>>>26,A&=67108863,this.words[M]=A}return b!==0&&(this.words[M]=b,this.length++),this},e.prototype.isZero=function(){return this.length===1&&this.words[0]===0},e.prototype.cmpn=function(o){var u=o<0;if(this.negative!==0&&!u)return-1;if(this.negative===0&&u)return 1;this._strip();var h;if(this.length>1)h=1;else{u&&(o=-o),t(o<=67108863,"Number is too big");var m=this.words[0]|0;h=m===o?0:m<o?-1:1}return this.negative!==0?-h|0:h},e.prototype.cmp=function(o){if(this.negative!==0&&o.negative===0)return-1;if(this.negative===0&&o.negative!==0)return 1;var u=this.ucmp(o);return this.negative!==0?-u|0:u},e.prototype.ucmp=function(o){if(this.length>o.length)return 1;if(this.length<o.length)return-1;for(var u=0,h=this.length-1;h>=0;h--){var m=this.words[h]|0,b=o.words[h]|0;if(m!==b){m<b?u=-1:m>b&&(u=1);break}}return u},e.prototype.gtn=function(o){return this.cmpn(o)===1},e.prototype.gt=function(o){return this.cmp(o)===1},e.prototype.gten=function(o){return this.cmpn(o)>=0},e.prototype.gte=function(o){return this.cmp(o)>=0},e.prototype.ltn=function(o){return this.cmpn(o)===-1},e.prototype.lt=function(o){return this.cmp(o)===-1},e.prototype.lten=function(o){return this.cmpn(o)<=0},e.prototype.lte=function(o){return this.cmp(o)<=0},e.prototype.eqn=function(o){return this.cmpn(o)===0},e.prototype.eq=function(o){return this.cmp(o)===0},e.red=function(o){return new G(o)},e.prototype.toRed=function(o){return t(!this.red,"Already a number in reduction context"),t(this.negative===0,"red works only with positives"),o.convertTo(this)._forceRed(o)},e.prototype.fromRed=function(){return t(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},e.prototype._forceRed=function(o){return this.red=o,this},e.prototype.forceRed=function(o){return t(!this.red,"Already a number in reduction context"),this._forceRed(o)},e.prototype.redAdd=function(o){return t(this.red,"redAdd works only with red numbers"),this.red.add(this,o)},e.prototype.redIAdd=function(o){return t(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,o)},e.prototype.redSub=function(o){return t(this.red,"redSub works only with red numbers"),this.red.sub(this,o)},e.prototype.redISub=function(o){return t(this.red,"redISub works only with red numbers"),this.red.isub(this,o)},e.prototype.redShl=function(o){return t(this.red,"redShl works only with red numbers"),this.red.shl(this,o)},e.prototype.redMul=function(o){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,o),this.red.mul(this,o)},e.prototype.redIMul=function(o){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,o),this.red.imul(this,o)},e.prototype.redSqr=function(){return t(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},e.prototype.redISqr=function(){return t(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},e.prototype.redSqrt=function(){return t(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},e.prototype.redInvm=function(){return t(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},e.prototype.redNeg=function(){return t(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},e.prototype.redPow=function(o){return t(this.red&&!o.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,o)};var W={k256:null,p224:null,p192:null,p25519:null};function L(v,o){this.name=v,this.p=new e(o,16),this.n=this.p.bitLength(),this.k=new e(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}L.prototype._tmp=function(){var o=new e(null);return o.words=new Array(Math.ceil(this.n/13)),o},L.prototype.ireduce=function(o){var u=o,h;do this.split(u,this.tmp),u=this.imulK(u),u=u.iadd(this.tmp),h=u.bitLength();while(h>this.n);var m=h<this.n?-1:u.ucmp(this.p);return m===0?(u.words[0]=0,u.length=1):m>0?u.isub(this.p):u.strip!==void 0?u.strip():u._strip(),u},L.prototype.split=function(o,u){o.iushrn(this.n,0,u)},L.prototype.imulK=function(o){return o.imul(this.k)};function X(){L.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}r(X,L),X.prototype.split=function(o,u){for(var h=4194303,m=Math.min(o.length,9),b=0;b<m;b++)u.words[b]=o.words[b];if(u.length=m,o.length<=9){o.words[0]=0,o.length=1;return}var M=o.words[9];for(u.words[u.length++]=M&h,b=10;b<o.length;b++){var A=o.words[b]|0;o.words[b-10]=(A&h)<<4|M>>>22,M=A}M>>>=22,o.words[b-10]=M,M===0&&o.length>10?o.length-=10:o.length-=9},X.prototype.imulK=function(o){o.words[o.length]=0,o.words[o.length+1]=0,o.length+=2;for(var u=0,h=0;h<o.length;h++){var m=o.words[h]|0;u+=m*977,o.words[h]=u&67108863,u=m*64+(u/67108864|0)}return o.words[o.length-1]===0&&(o.length--,o.words[o.length-1]===0&&o.length--),o};function tt(){L.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}r(tt,L);function it(){L.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}r(it,L);function at(){L.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}r(at,L),at.prototype.imulK=function(o){for(var u=0,h=0;h<o.length;h++){var m=(o.words[h]|0)*19+u,b=m&67108863;m>>>=26,o.words[h]=b,u=m}return u!==0&&(o.words[o.length++]=u),o},e._prime=function(o){if(W[o])return W[o];var u;if(o==="k256")u=new X;else if(o==="p224")u=new tt;else if(o==="p192")u=new it;else if(o==="p25519")u=new at;else throw new Error("Unknown prime "+o);return W[o]=u,u};function G(v){if(typeof v=="string"){var o=e._prime(v);this.m=o.p,this.prime=o}else t(v.gtn(1),"modulus must be greater than 1"),this.m=v,this.prime=null}G.prototype._verify1=function(o){t(o.negative===0,"red works only with positives"),t(o.red,"red works only with red numbers")},G.prototype._verify2=function(o,u){t((o.negative|u.negative)===0,"red works only with positives"),t(o.red&&o.red===u.red,"red works only with red numbers")},G.prototype.imod=function(o){return this.prime?this.prime.ireduce(o)._forceRed(this):(c(o,o.umod(this.m)._forceRed(this)),o)},G.prototype.neg=function(o){return o.isZero()?o.clone():this.m.sub(o)._forceRed(this)},G.prototype.add=function(o,u){this._verify2(o,u);var h=o.add(u);return h.cmp(this.m)>=0&&h.isub(this.m),h._forceRed(this)},G.prototype.iadd=function(o,u){this._verify2(o,u);var h=o.iadd(u);return h.cmp(this.m)>=0&&h.isub(this.m),h},G.prototype.sub=function(o,u){this._verify2(o,u);var h=o.sub(u);return h.cmpn(0)<0&&h.iadd(this.m),h._forceRed(this)},G.prototype.isub=function(o,u){this._verify2(o,u);var h=o.isub(u);return h.cmpn(0)<0&&h.iadd(this.m),h},G.prototype.shl=function(o,u){return this._verify1(o),this.imod(o.ushln(u))},G.prototype.imul=function(o,u){return this._verify2(o,u),this.imod(o.imul(u))},G.prototype.mul=function(o,u){return this._verify2(o,u),this.imod(o.mul(u))},G.prototype.isqr=function(o){return this.imul(o,o.clone())},G.prototype.sqr=function(o){return this.mul(o,o)},G.prototype.sqrt=function(o){if(o.isZero())return o.clone();var u=this.m.andln(3);if(t(u%2===1),u===3){var h=this.m.add(new e(1)).iushrn(2);return this.pow(o,h)}for(var m=this.m.subn(1),b=0;!m.isZero()&&m.andln(1)===0;)b++,m.iushrn(1);t(!m.isZero());var M=new e(1).toRed(this),A=M.redNeg(),g=this.m.subn(1).iushrn(1),a=this.m.bitLength();for(a=new e(2*a*a).toRed(this);this.pow(a,g).cmp(A)!==0;)a.redIAdd(A);for(var w=this.pow(a,m),R=this.pow(o,m.addn(1).iushrn(1)),D=this.pow(o,m),Z=b;D.cmp(M)!==0;){for(var z=D,J=0;z.cmp(M)!==0;J++)z=z.redSqr();t(J<Z);var N=this.pow(w,new e(1).iushln(Z-J-1));R=R.redMul(N),w=N.redSqr(),D=D.redMul(w),Z=J}return R},G.prototype.invm=function(o){var u=o._invmp(this.m);return u.negative!==0?(u.negative=0,this.imod(u).redNeg()):this.imod(u)},G.prototype.pow=function(o,u){if(u.isZero())return new e(1).toRed(this);if(u.cmpn(1)===0)return o.clone();var h=4,m=new Array(1<<h);m[0]=new e(1).toRed(this),m[1]=o;for(var b=2;b<m.length;b++)m[b]=this.mul(m[b-1],o);var M=m[0],A=0,g=0,a=u.bitLength()%26;for(a===0&&(a=26),b=u.length-1;b>=0;b--){for(var w=u.words[b],R=a-1;R>=0;R--){var D=w>>R&1;if(M!==m[0]&&(M=this.sqr(M)),D===0&&A===0){g=0;continue}A<<=1,A|=D,g++,!(g!==h&&(b!==0||R!==0))&&(M=this.mul(M,m[A]),g=0,A=0)}a=26}return M},G.prototype.convertTo=function(o){var u=o.umod(this.m);return u===o?u.clone():u},G.prototype.convertFrom=function(o){var u=o.clone();return u.red=null,u},e.mont=function(o){return new ot(o)};function ot(v){G.call(this,v),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new e(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)}r(ot,G),ot.prototype.convertTo=function(o){return this.imod(o.ushln(this.shift))},ot.prototype.convertFrom=function(o){var u=this.imod(o.mul(this.rinv));return u.red=null,u},ot.prototype.imul=function(o,u){if(o.isZero()||u.isZero())return o.words[0]=0,o.length=1,o;var h=o.imul(u),m=h.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),b=h.isub(m).iushrn(this.shift),M=b;return b.cmp(this.m)>=0?M=b.isub(this.m):b.cmpn(0)<0&&(M=b.iadd(this.m)),M._forceRed(this)},ot.prototype.mul=function(o,u){if(o.isZero()||u.isZero())return new e(0)._forceRed(this);var h=o.mul(u),m=h.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),b=h.isub(m).iushrn(this.shift),M=b;return b.cmp(this.m)>=0?M=b.isub(this.m):b.cmpn(0)<0&&(M=b.iadd(this.m)),M._forceRed(this)},ot.prototype.invm=function(o){var u=this.imod(o._invmp(this.m).mul(this.r2));return u._forceRed(this)}})(typeof Pi>"u"||Pi,lr)});import{SdkWrapper as Po}from"@cetusprotocol/common-sdk";import{FullRpcUrlMainnet as on,GraphRpcUrlMainnet as sn}from"@cetusprotocol/common-sdk";var ar={env:"mainnet",full_rpc_url:on,graph_rpc_url:sn,dlmm_pool:{package_id:"0x5664f9d3fd82c84023870cfbda8ea84e14c8dd56ce557ad2116e0668581a682b",published_at:"0x44d0fb760f9f7ce532a4a97abddf2e7982c9b9b50ac94cf62de8f4d11356d306",version:5,config:{registry_id:"0xb1d55e7d895823c65f98d99b81a69436cf7d1638629c9ccb921326039cda1f1b",pools_id:"0xc3683b2356cac6423e9ecaea20955c7cc193998b016e5b884730ed1192174991",global_config_id:"0xf31b605d117f959b9730e8c07b08b856cb05143c5e81d5751c90d2979e82f599",versioned_id:"0x05370b2d656612dd5759cbe80463de301e3b94a921dfc72dd9daa2ecdeb2d0a8",admin_cap_id:"0xc4c42bc31cb54beb679dccd547f8bdb970cb6dc989bd1f85a4fed4812ed95d6e",partners_id:"0x5c0affc8d363b6abb1f32790c229165215f4edead89a9bc7cd95dad717b4296a"}},dlmm_router:{package_id:"0x8d389fa25cb08ebc5e520bc520ed394eed9e62b56b7868acb398bf298b8a76f3",published_at:"0xdb974d2654a62bb0668f58ee7919b5e41566a6c3336c3a006a412d5137487c67",version:3}};import{Transaction as Ke}from"@mysten/sui/transactions";import{asUintN as Fr,CLOCK_ADDRESS as so,createFullClient as ao,d as Ni,deriveDynamicFieldIdByType as lo,DETAILS_KEYS as te,fixCoinType as Nr,getObjectFields as qr,getPackagerConfigs as Lr,isSortedSymbols as uo}from"@cetusprotocol/common-sdk";import{BaseError as an}from"@cetusprotocol/common-sdk";var _e=class extends an{constructor(i,t,r){super(i,t||"UnknownError",r)}static isDlmmErrorCode(i,t){return this.isErrorCode(i,t)}},V=(n,i,t)=>{let r={...t,stack:i instanceof Error?i.stack:void 0};throw i instanceof Error?new _e(i.message,n,r):new _e(i,n,r)};var Sr=Mi(ke());import{asIntN as Ae,d as Ti,DETAILS_KEYS as pe,extractStructTagFromType as Ci,fixCoinType as ne,getObjectFields as ki,getObjectType as Br,MathUtil as ro}from"@cetusprotocol/common-sdk";var we=9e15,fe=1e9,Ai="0123456789abcdef",Fe="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Ne="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Bi={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-we,maxE:we,crypto:!1},cr,se,K=!0,Le="[DecimalError] ",de=Le+"Invalid argument: ",hr=Le+"Precision limit exceeded",pr=Le+"crypto unavailable",mr="[object Decimal]",Kt=Math.floor,Ut=Math.pow,ln=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,un=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,dn=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,_r=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Xt=1e7,Q=7,fn=9007199254740991,cn=Fe.length-1,Si=Ne.length-1,I={toStringTag:mr};I.absoluteValue=I.abs=function(){var n=new this.constructor(this);return n.s<0&&(n.s=1),U(n)};I.ceil=function(){return U(new this.constructor(this),this.e+1,2)};I.clampedTo=I.clamp=function(n,i){var t,r=this,e=r.constructor;if(n=new e(n),i=new e(i),!n.s||!i.s)return new e(NaN);if(n.gt(i))throw Error(de+i);return t=r.cmp(n),t<0?n:r.cmp(i)>0?i:new e(r)};I.comparedTo=I.cmp=function(n){var i,t,r,e,s=this,l=s.d,d=(n=new s.constructor(n)).d,f=s.s,c=n.s;if(!l||!d)return!f||!c?NaN:f!==c?f:l===d?0:!l^f<0?1:-1;if(!l[0]||!d[0])return l[0]?f:d[0]?-c:0;if(f!==c)return f;if(s.e!==n.e)return s.e>n.e^f<0?1:-1;for(r=l.length,e=d.length,i=0,t=r<e?r:e;i<t;++i)if(l[i]!==d[i])return l[i]>d[i]^f<0?1:-1;return r===e?0:r>e^f<0?1:-1};I.cosine=I.cos=function(){var n,i,t=this,r=t.constructor;return t.d?t.d[0]?(n=r.precision,i=r.rounding,r.precision=n+Math.max(t.e,t.sd())+Q,r.rounding=1,t=hn(r,yr(r,t)),r.precision=n,r.rounding=i,U(se==2||se==3?t.neg():t,n,i,!0)):new r(1):new r(NaN)};I.cubeRoot=I.cbrt=function(){var n,i,t,r,e,s,l,d,f,c,p=this,_=p.constructor;if(!p.isFinite()||p.isZero())return new _(p);for(K=!1,s=p.s*Ut(p.s*p,1/3),!s||Math.abs(s)==1/0?(t=Qt(p.d),n=p.e,(s=(n-t.length+1)%3)&&(t+=s==1||s==-2?"0":"00"),s=Ut(t,1/3),n=Kt((n+1)/3)-(n%3==(n<0?-1:2)),s==1/0?t="5e"+n:(t=s.toExponential(),t=t.slice(0,t.indexOf("e")+1)+n),r=new _(t),r.s=p.s):r=new _(s.toString()),l=(n=_.precision)+3;;)if(d=r,f=d.times(d).times(d),c=f.plus(p),r=st(c.plus(p).times(d),c.plus(f),l+2,1),Qt(d.d).slice(0,l)===(t=Qt(r.d)).slice(0,l))if(t=t.slice(l-3,l+1),t=="9999"||!e&&t=="4999"){if(!e&&(U(d,n+1,0),d.times(d).times(d).eq(p))){r=d;break}l+=4,e=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(U(r,n+1,1),i=!r.times(r).times(r).eq(p));break}return K=!0,U(r,n,_.rounding,i)};I.decimalPlaces=I.dp=function(){var n,i=this.d,t=NaN;if(i){if(n=i.length-1,t=(n-Kt(this.e/Q))*Q,n=i[n],n)for(;n%10==0;n/=10)t--;t<0&&(t=0)}return t};I.dividedBy=I.div=function(n){return st(this,new this.constructor(n))};I.dividedToIntegerBy=I.divToInt=function(n){var i=this,t=i.constructor;return U(st(i,new t(n),0,1,1),t.precision,t.rounding)};I.equals=I.eq=function(n){return this.cmp(n)===0};I.floor=function(){return U(new this.constructor(this),this.e+1,3)};I.greaterThan=I.gt=function(n){return this.cmp(n)>0};I.greaterThanOrEqualTo=I.gte=function(n){var i=this.cmp(n);return i==1||i===0};I.hyperbolicCosine=I.cosh=function(){var n,i,t,r,e,s=this,l=s.constructor,d=new l(1);if(!s.isFinite())return new l(s.s?1/0:NaN);if(s.isZero())return d;t=l.precision,r=l.rounding,l.precision=t+Math.max(s.e,s.sd())+4,l.rounding=1,e=s.d.length,e<32?(n=Math.ceil(e/3),i=(1/We(4,n)).toString()):(n=16,i="2.3283064365386962890625e-10"),s=ve(l,1,s.times(i),new l(1),!0);for(var f,c=n,p=new l(8);c--;)f=s.times(s),s=d.minus(f.times(p.minus(f.times(p))));return U(s,l.precision=t,l.rounding=r,!0)};I.hyperbolicSine=I.sinh=function(){var n,i,t,r,e=this,s=e.constructor;if(!e.isFinite()||e.isZero())return new s(e);if(i=s.precision,t=s.rounding,s.precision=i+Math.max(e.e,e.sd())+4,s.rounding=1,r=e.d.length,r<3)e=ve(s,2,e,e,!0);else{n=1.4*Math.sqrt(r),n=n>16?16:n|0,e=e.times(1/We(5,n)),e=ve(s,2,e,e,!0);for(var l,d=new s(5),f=new s(16),c=new s(20);n--;)l=e.times(e),e=e.times(d.plus(l.times(f.times(l).plus(c))))}return s.precision=i,s.rounding=t,U(e,i,t,!0)};I.hyperbolicTangent=I.tanh=function(){var n,i,t=this,r=t.constructor;return t.isFinite()?t.isZero()?new r(t):(n=r.precision,i=r.rounding,r.precision=n+7,r.rounding=1,st(t.sinh(),t.cosh(),r.precision=n,r.rounding=i)):new r(t.s)};I.inverseCosine=I.acos=function(){var n=this,i=n.constructor,t=n.abs().cmp(1),r=i.precision,e=i.rounding;return t!==-1?t===0?n.isNeg()?ie(i,r,e):new i(0):new i(NaN):n.isZero()?ie(i,r+4,e).times(.5):(i.precision=r+6,i.rounding=1,n=new i(1).minus(n).div(n.plus(1)).sqrt().atan(),i.precision=r,i.rounding=e,n.times(2))};I.inverseHyperbolicCosine=I.acosh=function(){var n,i,t=this,r=t.constructor;return t.lte(1)?new r(t.eq(1)?0:NaN):t.isFinite()?(n=r.precision,i=r.rounding,r.precision=n+Math.max(Math.abs(t.e),t.sd())+4,r.rounding=1,K=!1,t=t.times(t).minus(1).sqrt().plus(t),K=!0,r.precision=n,r.rounding=i,t.ln()):new r(t)};I.inverseHyperbolicSine=I.asinh=function(){var n,i,t=this,r=t.constructor;return!t.isFinite()||t.isZero()?new r(t):(n=r.precision,i=r.rounding,r.precision=n+2*Math.max(Math.abs(t.e),t.sd())+6,r.rounding=1,K=!1,t=t.times(t).plus(1).sqrt().plus(t),K=!0,r.precision=n,r.rounding=i,t.ln())};I.inverseHyperbolicTangent=I.atanh=function(){var n,i,t,r,e=this,s=e.constructor;return e.isFinite()?e.e>=0?new s(e.abs().eq(1)?e.s/0:e.isZero()?e:NaN):(n=s.precision,i=s.rounding,r=e.sd(),Math.max(r,n)<2*-e.e-1?U(new s(e),n,i,!0):(s.precision=t=r-e.e,e=st(e.plus(1),new s(1).minus(e),t+n,1),s.precision=n+4,s.rounding=1,e=e.ln(),s.precision=n,s.rounding=i,e.times(.5))):new s(NaN)};I.inverseSine=I.asin=function(){var n,i,t,r,e=this,s=e.constructor;return e.isZero()?new s(e):(i=e.abs().cmp(1),t=s.precision,r=s.rounding,i!==-1?i===0?(n=ie(s,t+4,r).times(.5),n.s=e.s,n):new s(NaN):(s.precision=t+6,s.rounding=1,e=e.div(new s(1).minus(e.times(e)).sqrt().plus(1)).atan(),s.precision=t,s.rounding=r,e.times(2)))};I.inverseTangent=I.atan=function(){var n,i,t,r,e,s,l,d,f,c=this,p=c.constructor,_=p.precision,y=p.rounding;if(c.isFinite()){if(c.isZero())return new p(c);if(c.abs().eq(1)&&_+4<=Si)return l=ie(p,_+4,y).times(.25),l.s=c.s,l}else{if(!c.s)return new p(NaN);if(_+4<=Si)return l=ie(p,_+4,y).times(.5),l.s=c.s,l}for(p.precision=d=_+10,p.rounding=1,t=Math.min(28,d/Q+2|0),n=t;n;--n)c=c.div(c.times(c).plus(1).sqrt().plus(1));for(K=!1,i=Math.ceil(d/Q),r=1,f=c.times(c),l=new p(c),e=c;n!==-1;)if(e=e.times(f),s=l.minus(e.div(r+=2)),e=e.times(f),l=s.plus(e.div(r+=2)),l.d[i]!==void 0)for(n=i;l.d[n]===s.d[n]&&n--;);return t&&(l=l.times(2<<t-1)),K=!0,U(l,p.precision=_,p.rounding=y,!0)};I.isFinite=function(){return!!this.d};I.isInteger=I.isInt=function(){return!!this.d&&Kt(this.e/Q)>this.d.length-2};I.isNaN=function(){return!this.s};I.isNegative=I.isNeg=function(){return this.s<0};I.isPositive=I.isPos=function(){return this.s>0};I.isZero=function(){return!!this.d&&this.d[0]===0};I.lessThan=I.lt=function(n){return this.cmp(n)<0};I.lessThanOrEqualTo=I.lte=function(n){return this.cmp(n)<1};I.logarithm=I.log=function(n){var i,t,r,e,s,l,d,f,c=this,p=c.constructor,_=p.precision,y=p.rounding,P=5;if(n==null)n=new p(10),i=!0;else{if(n=new p(n),t=n.d,n.s<0||!t||!t[0]||n.eq(1))return new p(NaN);i=n.eq(10)}if(t=c.d,c.s<0||!t||!t[0]||c.eq(1))return new p(t&&!t[0]?-1/0:c.s!=1?NaN:t?0:1/0);if(i)if(t.length>1)s=!0;else{for(e=t[0];e%10===0;)e/=10;s=e!==1}if(K=!1,d=_+P,l=ue(c,d),r=i?qe(p,d+10):ue(n,d),f=st(l,r,d,1),Ie(f.d,e=_,y))do if(d+=10,l=ue(c,d),r=i?qe(p,d+10):ue(n,d),f=st(l,r,d,1),!s){+Qt(f.d).slice(e+1,e+15)+1==1e14&&(f=U(f,_+1,0));break}while(Ie(f.d,e+=10,y));return K=!0,U(f,_,y)};I.minus=I.sub=function(n){var i,t,r,e,s,l,d,f,c,p,_,y,P=this,B=P.constructor;if(n=new B(n),!P.d||!n.d)return!P.s||!n.s?n=new B(NaN):P.d?n.s=-n.s:n=new B(n.d||P.s!==n.s?P:NaN),n;if(P.s!=n.s)return n.s=-n.s,P.plus(n);if(c=P.d,y=n.d,d=B.precision,f=B.rounding,!c[0]||!y[0]){if(y[0])n.s=-n.s;else if(c[0])n=new B(P);else return new B(f===3?-0:0);return K?U(n,d,f):n}if(t=Kt(n.e/Q),p=Kt(P.e/Q),c=c.slice(),s=p-t,s){for(_=s<0,_?(i=c,s=-s,l=y.length):(i=y,t=p,l=c.length),r=Math.max(Math.ceil(d/Q),l)+2,s>r&&(s=r,i.length=1),i.reverse(),r=s;r--;)i.push(0);i.reverse()}else{for(r=c.length,l=y.length,_=r<l,_&&(l=r),r=0;r<l;r++)if(c[r]!=y[r]){_=c[r]<y[r];break}s=0}for(_&&(i=c,c=y,y=i,n.s=-n.s),l=c.length,r=y.length-l;r>0;--r)c[l++]=0;for(r=y.length;r>s;){if(c[--r]<y[r]){for(e=r;e&&c[--e]===0;)c[e]=Xt-1;--c[e],c[r]+=Xt}c[r]-=y[r]}for(;c[--l]===0;)c.pop();for(;c[0]===0;c.shift())--t;return c[0]?(n.d=c,n.e=je(c,t),K?U(n,d,f):n):new B(f===3?-0:0)};I.modulo=I.mod=function(n){var i,t=this,r=t.constructor;return n=new r(n),!t.d||!n.s||n.d&&!n.d[0]?new r(NaN):!n.d||t.d&&!t.d[0]?U(new r(t),r.precision,r.rounding):(K=!1,r.modulo==9?(i=st(t,n.abs(),0,3,1),i.s*=n.s):i=st(t,n,0,r.modulo,1),i=i.times(n),K=!0,t.minus(i))};I.naturalExponential=I.exp=function(){return Ii(this)};I.naturalLogarithm=I.ln=function(){return ue(this)};I.negated=I.neg=function(){var n=new this.constructor(this);return n.s=-n.s,U(n)};I.plus=I.add=function(n){var i,t,r,e,s,l,d,f,c,p,_=this,y=_.constructor;if(n=new y(n),!_.d||!n.d)return!_.s||!n.s?n=new y(NaN):_.d||(n=new y(n.d||_.s===n.s?_:NaN)),n;if(_.s!=n.s)return n.s=-n.s,_.minus(n);if(c=_.d,p=n.d,d=y.precision,f=y.rounding,!c[0]||!p[0])return p[0]||(n=new y(_)),K?U(n,d,f):n;if(s=Kt(_.e/Q),r=Kt(n.e/Q),c=c.slice(),e=s-r,e){for(e<0?(t=c,e=-e,l=p.length):(t=p,r=s,l=c.length),s=Math.ceil(d/Q),l=s>l?s+1:l+1,e>l&&(e=l,t.length=1),t.reverse();e--;)t.push(0);t.reverse()}for(l=c.length,e=p.length,l-e<0&&(e=l,t=p,p=c,c=t),i=0;e;)i=(c[--e]=c[e]+p[e]+i)/Xt|0,c[e]%=Xt;for(i&&(c.unshift(i),++r),l=c.length;c[--l]==0;)c.pop();return n.d=c,n.e=je(c,r),K?U(n,d,f):n};I.precision=I.sd=function(n){var i,t=this;if(n!==void 0&&n!==!!n&&n!==1&&n!==0)throw Error(de+n);return t.d?(i=gr(t.d),n&&t.e+1>i&&(i=t.e+1)):i=NaN,i};I.round=function(){var n=this,i=n.constructor;return U(new i(n),n.e+1,i.rounding)};I.sine=I.sin=function(){var n,i,t=this,r=t.constructor;return t.isFinite()?t.isZero()?new r(t):(n=r.precision,i=r.rounding,r.precision=n+Math.max(t.e,t.sd())+Q,r.rounding=1,t=mn(r,yr(r,t)),r.precision=n,r.rounding=i,U(se>2?t.neg():t,n,i,!0)):new r(NaN)};I.squareRoot=I.sqrt=function(){var n,i,t,r,e,s,l=this,d=l.d,f=l.e,c=l.s,p=l.constructor;if(c!==1||!d||!d[0])return new p(!c||c<0&&(!d||d[0])?NaN:d?l:1/0);for(K=!1,c=Math.sqrt(+l),c==0||c==1/0?(i=Qt(d),(i.length+f)%2==0&&(i+="0"),c=Math.sqrt(i),f=Kt((f+1)/2)-(f<0||f%2),c==1/0?i="5e"+f:(i=c.toExponential(),i=i.slice(0,i.indexOf("e")+1)+f),r=new p(i)):r=new p(c.toString()),t=(f=p.precision)+3;;)if(s=r,r=s.plus(st(l,s,t+2,1)).times(.5),Qt(s.d).slice(0,t)===(i=Qt(r.d)).slice(0,t))if(i=i.slice(t-3,t+1),i=="9999"||!e&&i=="4999"){if(!e&&(U(s,f+1,0),s.times(s).eq(l))){r=s;break}t+=4,e=1}else{(!+i||!+i.slice(1)&&i.charAt(0)=="5")&&(U(r,f+1,1),n=!r.times(r).eq(l));break}return K=!0,U(r,f,p.rounding,n)};I.tangent=I.tan=function(){var n,i,t=this,r=t.constructor;return t.isFinite()?t.isZero()?new r(t):(n=r.precision,i=r.rounding,r.precision=n+10,r.rounding=1,t=t.sin(),t.s=1,t=st(t,new r(1).minus(t.times(t)).sqrt(),n+10,0),r.precision=n,r.rounding=i,U(se==2||se==4?t.neg():t,n,i,!0)):new r(NaN)};I.times=I.mul=function(n){var i,t,r,e,s,l,d,f,c,p=this,_=p.constructor,y=p.d,P=(n=new _(n)).d;if(n.s*=p.s,!y||!y[0]||!P||!P[0])return new _(!n.s||y&&!y[0]&&!P||P&&!P[0]&&!y?NaN:!y||!P?n.s/0:n.s*0);for(t=Kt(p.e/Q)+Kt(n.e/Q),f=y.length,c=P.length,f<c&&(s=y,y=P,P=s,l=f,f=c,c=l),s=[],l=f+c,r=l;r--;)s.push(0);for(r=c;--r>=0;){for(i=0,e=f+r;e>r;)d=s[e]+P[r]*y[e-r-1]+i,s[e--]=d%Xt|0,i=d/Xt|0;s[e]=(s[e]+i)%Xt|0}for(;!s[--l];)s.pop();return i?++t:s.shift(),n.d=s,n.e=je(s,t),K?U(n,_.precision,_.rounding):n};I.toBinary=function(n,i){return Ei(this,2,n,i)};I.toDecimalPlaces=I.toDP=function(n,i){var t=this,r=t.constructor;return t=new r(t),n===void 0?t:($t(n,0,fe),i===void 0?i=r.rounding:$t(i,0,8),U(t,n+t.e+1,i))};I.toExponential=function(n,i){var t,r=this,e=r.constructor;return n===void 0?t=re(r,!0):($t(n,0,fe),i===void 0?i=e.rounding:$t(i,0,8),r=U(new e(r),n+1,i),t=re(r,!0,n+1)),r.isNeg()&&!r.isZero()?"-"+t:t};I.toFixed=function(n,i){var t,r,e=this,s=e.constructor;return n===void 0?t=re(e):($t(n,0,fe),i===void 0?i=s.rounding:$t(i,0,8),r=U(new s(e),n+e.e+1,i),t=re(r,!1,n+r.e+1)),e.isNeg()&&!e.isZero()?"-"+t:t};I.toFraction=function(n){var i,t,r,e,s,l,d,f,c,p,_,y,P=this,B=P.d,S=P.constructor;if(!B)return new S(P);if(c=t=new S(1),r=f=new S(0),i=new S(r),s=i.e=gr(B)-P.e-1,l=s%Q,i.d[0]=Ut(10,l<0?Q+l:l),n==null)n=s>0?i:c;else{if(d=new S(n),!d.isInt()||d.lt(c))throw Error(de+d);n=d.gt(i)?s>0?i:c:d}for(K=!1,d=new S(Qt(B)),p=S.precision,S.precision=s=B.length*Q*2;_=st(d,i,0,1,1),e=t.plus(_.times(r)),e.cmp(n)!=1;)t=r,r=e,e=c,c=f.plus(_.times(e)),f=e,e=i,i=d.minus(_.times(e)),d=e;return e=st(n.minus(t),r,0,1,1),f=f.plus(e.times(c)),t=t.plus(e.times(r)),f.s=c.s=P.s,y=st(c,r,s,1).minus(P).abs().cmp(st(f,t,s,1).minus(P).abs())<1?[c,r]:[f,t],S.precision=p,K=!0,y};I.toHexadecimal=I.toHex=function(n,i){return Ei(this,16,n,i)};I.toNearest=function(n,i){var t=this,r=t.constructor;if(t=new r(t),n==null){if(!t.d)return t;n=new r(1),i=r.rounding}else{if(n=new r(n),i===void 0?i=r.rounding:$t(i,0,8),!t.d)return n.s?t:n;if(!n.d)return n.s&&(n.s=t.s),n}return n.d[0]?(K=!1,t=st(t,n,0,i,1).times(n),K=!0,U(t)):(n.s=t.s,t=n),t};I.toNumber=function(){return+this};I.toOctal=function(n,i){return Ei(this,8,n,i)};I.toPower=I.pow=function(n){var i,t,r,e,s,l,d=this,f=d.constructor,c=+(n=new f(n));if(!d.d||!n.d||!d.d[0]||!n.d[0])return new f(Ut(+d,c));if(d=new f(d),d.eq(1))return d;if(r=f.precision,s=f.rounding,n.eq(1))return U(d,r,s);if(i=Kt(n.e/Q),i>=n.d.length-1&&(t=c<0?-c:c)<=fn)return e=br(f,d,t,r),n.s<0?new f(1).div(e):U(e,r,s);if(l=d.s,l<0){if(i<n.d.length-1)return new f(NaN);if((n.d[i]&1)==0&&(l=1),d.e==0&&d.d[0]==1&&d.d.length==1)return d.s=l,d}return t=Ut(+d,c),i=t==0||!isFinite(t)?Kt(c*(Math.log("0."+Qt(d.d))/Math.LN10+d.e+1)):new f(t+"").e,i>f.maxE+1||i<f.minE-1?new f(i>0?l/0:0):(K=!1,f.rounding=d.s=1,t=Math.min(12,(i+"").length),e=Ii(n.times(ue(d,r+t)),r),e.d&&(e=U(e,r+5,1),Ie(e.d,r,s)&&(i=r+10,e=U(Ii(n.times(ue(d,i+t)),i),i+5,1),+Qt(e.d).slice(r+1,r+15)+1==1e14&&(e=U(e,r+1,0)))),e.s=l,K=!0,f.rounding=s,U(e,r,s))};I.toPrecision=function(n,i){var t,r=this,e=r.constructor;return n===void 0?t=re(r,r.e<=e.toExpNeg||r.e>=e.toExpPos):($t(n,1,fe),i===void 0?i=e.rounding:$t(i,0,8),r=U(new e(r),n,i),t=re(r,n<=r.e||r.e<=e.toExpNeg,n)),r.isNeg()&&!r.isZero()?"-"+t:t};I.toSignificantDigits=I.toSD=function(n,i){var t=this,r=t.constructor;return n===void 0?(n=r.precision,i=r.rounding):($t(n,1,fe),i===void 0?i=r.rounding:$t(i,0,8)),U(new r(t),n,i)};I.toString=function(){var n=this,i=n.constructor,t=re(n,n.e<=i.toExpNeg||n.e>=i.toExpPos);return n.isNeg()&&!n.isZero()?"-"+t:t};I.truncated=I.trunc=function(){return U(new this.constructor(this),this.e+1,1)};I.valueOf=I.toJSON=function(){var n=this,i=n.constructor,t=re(n,n.e<=i.toExpNeg||n.e>=i.toExpPos);return n.isNeg()?"-"+t:t};function Qt(n){var i,t,r,e=n.length-1,s="",l=n[0];if(e>0){for(s+=l,i=1;i<e;i++)r=n[i]+"",t=Q-r.length,t&&(s+=le(t)),s+=r;l=n[i],r=l+"",t=Q-r.length,t&&(s+=le(t))}else if(l===0)return"0";for(;l%10===0;)l/=10;return s+l}function $t(n,i,t){if(n!==~~n||n<i||n>t)throw Error(de+n)}function Ie(n,i,t,r){var e,s,l,d;for(s=n[0];s>=10;s/=10)--i;return--i<0?(i+=Q,e=0):(e=Math.ceil((i+1)/Q),i%=Q),s=Ut(10,Q-i),d=n[e]%s|0,r==null?i<3?(i==0?d=d/100|0:i==1&&(d=d/10|0),l=t<4&&d==99999||t>3&&d==49999||d==5e4||d==0):l=(t<4&&d+1==s||t>3&&d+1==s/2)&&(n[e+1]/s/100|0)==Ut(10,i-2)-1||(d==s/2||d==0)&&(n[e+1]/s/100|0)==0:i<4?(i==0?d=d/1e3|0:i==1?d=d/100|0:i==2&&(d=d/10|0),l=(r||t<4)&&d==9999||!r&&t>3&&d==4999):l=((r||t<4)&&d+1==s||!r&&t>3&&d+1==s/2)&&(n[e+1]/s/1e3|0)==Ut(10,i-3)-1,l}function Re(n,i,t){for(var r,e=[0],s,l=0,d=n.length;l<d;){for(s=e.length;s--;)e[s]*=i;for(e[0]+=Ai.indexOf(n.charAt(l++)),r=0;r<e.length;r++)e[r]>t-1&&(e[r+1]===void 0&&(e[r+1]=0),e[r+1]+=e[r]/t|0,e[r]%=t)}return e.reverse()}function hn(n,i){var t,r,e;if(i.isZero())return i;r=i.d.length,r<32?(t=Math.ceil(r/3),e=(1/We(4,t)).toString()):(t=16,e="2.3283064365386962890625e-10"),n.precision+=t,i=ve(n,1,i.times(e),new n(1));for(var s=t;s--;){var l=i.times(i);i=l.times(l).minus(l).times(8).plus(1)}return n.precision-=t,i}var st=(function(){function n(r,e,s){var l,d=0,f=r.length;for(r=r.slice();f--;)l=r[f]*e+d,r[f]=l%s|0,d=l/s|0;return d&&r.unshift(d),r}function i(r,e,s,l){var d,f;if(s!=l)f=s>l?1:-1;else for(d=f=0;d<s;d++)if(r[d]!=e[d]){f=r[d]>e[d]?1:-1;break}return f}function t(r,e,s,l){for(var d=0;s--;)r[s]-=d,d=r[s]<e[s]?1:0,r[s]=d*l+r[s]-e[s];for(;!r[0]&&r.length>1;)r.shift()}return function(r,e,s,l,d,f){var c,p,_,y,P,B,S,T,C,k,O,x,W,L,X,tt,it,at,G,ot,v=r.constructor,o=r.s==e.s?1:-1,u=r.d,h=e.d;if(!u||!u[0]||!h||!h[0])return new v(!r.s||!e.s||(u?h&&u[0]==h[0]:!h)?NaN:u&&u[0]==0||!h?o*0:o/0);for(f?(P=1,p=r.e-e.e):(f=Xt,P=Q,p=Kt(r.e/P)-Kt(e.e/P)),G=h.length,it=u.length,C=new v(o),k=C.d=[],_=0;h[_]==(u[_]||0);_++);if(h[_]>(u[_]||0)&&p--,s==null?(L=s=v.precision,l=v.rounding):d?L=s+(r.e-e.e)+1:L=s,L<0)k.push(1),B=!0;else{if(L=L/P+2|0,_=0,G==1){for(y=0,h=h[0],L++;(_<it||y)&&L--;_++)X=y*f+(u[_]||0),k[_]=X/h|0,y=X%h|0;B=y||_<it}else{for(y=f/(h[0]+1)|0,y>1&&(h=n(h,y,f),u=n(u,y,f),G=h.length,it=u.length),tt=G,O=u.slice(0,G),x=O.length;x<G;)O[x++]=0;ot=h.slice(),ot.unshift(0),at=h[0],h[1]>=f/2&&++at;do y=0,c=i(h,O,G,x),c<0?(W=O[0],G!=x&&(W=W*f+(O[1]||0)),y=W/at|0,y>1?(y>=f&&(y=f-1),S=n(h,y,f),T=S.length,x=O.length,c=i(S,O,T,x),c==1&&(y--,t(S,G<T?ot:h,T,f))):(y==0&&(c=y=1),S=h.slice()),T=S.length,T<x&&S.unshift(0),t(O,S,x,f),c==-1&&(x=O.length,c=i(h,O,G,x),c<1&&(y++,t(O,G<x?ot:h,x,f))),x=O.length):c===0&&(y++,O=[0]),k[_++]=y,c&&O[0]?O[x++]=u[tt]||0:(O=[u[tt]],x=1);while((tt++<it||O[0]!==void 0)&&L--);B=O[0]!==void 0}k[0]||k.shift()}if(P==1)C.e=p,cr=B;else{for(_=1,y=k[0];y>=10;y/=10)_++;C.e=_+p*P-1,U(C,d?s+C.e+1:s,l,B)}return C}})();function U(n,i,t,r){var e,s,l,d,f,c,p,_,y,P=n.constructor;t:if(i!=null){if(_=n.d,!_)return n;for(e=1,d=_[0];d>=10;d/=10)e++;if(s=i-e,s<0)s+=Q,l=i,p=_[y=0],f=p/Ut(10,e-l-1)%10|0;else if(y=Math.ceil((s+1)/Q),d=_.length,y>=d)if(r){for(;d++<=y;)_.push(0);p=f=0,e=1,s%=Q,l=s-Q+1}else break t;else{for(p=d=_[y],e=1;d>=10;d/=10)e++;s%=Q,l=s-Q+e,f=l<0?0:p/Ut(10,e-l-1)%10|0}if(r=r||i<0||_[y+1]!==void 0||(l<0?p:p%Ut(10,e-l-1)),c=t<4?(f||r)&&(t==0||t==(n.s<0?3:2)):f>5||f==5&&(t==4||r||t==6&&(s>0?l>0?p/Ut(10,e-l):0:_[y-1])%10&1||t==(n.s<0?8:7)),i<1||!_[0])return _.length=0,c?(i-=n.e+1,_[0]=Ut(10,(Q-i%Q)%Q),n.e=-i||0):_[0]=n.e=0,n;if(s==0?(_.length=y,d=1,y--):(_.length=y+1,d=Ut(10,Q-s),_[y]=l>0?(p/Ut(10,e-l)%Ut(10,l)|0)*d:0),c)for(;;)if(y==0){for(s=1,l=_[0];l>=10;l/=10)s++;for(l=_[0]+=d,d=1;l>=10;l/=10)d++;s!=d&&(n.e++,_[0]==Xt&&(_[0]=1));break}else{if(_[y]+=d,_[y]!=Xt)break;_[y--]=0,d=1}for(s=_.length;_[--s]===0;)_.pop()}return K&&(n.e>P.maxE?(n.d=null,n.e=NaN):n.e<P.minE&&(n.e=0,n.d=[0])),n}function re(n,i,t){if(!n.isFinite())return vr(n);var r,e=n.e,s=Qt(n.d),l=s.length;return i?(t&&(r=t-l)>0?s=s.charAt(0)+"."+s.slice(1)+le(r):l>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(n.e<0?"e":"e+")+n.e):e<0?(s="0."+le(-e-1)+s,t&&(r=t-l)>0&&(s+=le(r))):e>=l?(s+=le(e+1-l),t&&(r=t-e-1)>0&&(s=s+"."+le(r))):((r=e+1)<l&&(s=s.slice(0,r)+"."+s.slice(r)),t&&(r=t-l)>0&&(e+1===l&&(s+="."),s+=le(r))),s}function je(n,i){var t=n[0];for(i*=Q;t>=10;t/=10)i++;return i}function qe(n,i,t){if(i>cn)throw K=!0,t&&(n.precision=t),Error(hr);return U(new n(Fe),i,1,!0)}function ie(n,i,t){if(i>Si)throw Error(hr);return U(new n(Ne),i,t,!0)}function gr(n){var i=n.length-1,t=i*Q+1;if(i=n[i],i){for(;i%10==0;i/=10)t--;for(i=n[0];i>=10;i/=10)t++}return t}function le(n){for(var i="";n--;)i+="0";return i}function br(n,i,t,r){var e,s=new n(1),l=Math.ceil(r/Q+4);for(K=!1;;){if(t%2&&(s=s.times(i),dr(s.d,l)&&(e=!0)),t=Kt(t/2),t===0){t=s.d.length-1,e&&s.d[t]===0&&++s.d[t];break}i=i.times(i),dr(i.d,l)}return K=!0,s}function ur(n){return n.d[n.d.length-1]&1}function wr(n,i,t){for(var r,e,s=new n(i[0]),l=0;++l<i.length;){if(e=new n(i[l]),!e.s){s=e;break}r=s.cmp(e),(r===t||r===0&&s.s===t)&&(s=e)}return s}function Ii(n,i){var t,r,e,s,l,d,f,c=0,p=0,_=0,y=n.constructor,P=y.rounding,B=y.precision;if(!n.d||!n.d[0]||n.e>17)return new y(n.d?n.d[0]?n.s<0?0:1/0:1:n.s?n.s<0?0:n:NaN);for(i==null?(K=!1,f=B):f=i,d=new y(.03125);n.e>-2;)n=n.times(d),_+=5;for(r=Math.log(Ut(2,_))/Math.LN10*2+5|0,f+=r,t=s=l=new y(1),y.precision=f;;){if(s=U(s.times(n),f,1),t=t.times(++p),d=l.plus(st(s,t,f,1)),Qt(d.d).slice(0,f)===Qt(l.d).slice(0,f)){for(e=_;e--;)l=U(l.times(l),f,1);if(i==null)if(c<3&&Ie(l.d,f-r,P,c))y.precision=f+=10,t=s=d=new y(1),p=0,c++;else return U(l,y.precision=B,P,K=!0);else return y.precision=B,l}l=d}}function ue(n,i){var t,r,e,s,l,d,f,c,p,_,y,P=1,B=10,S=n,T=S.d,C=S.constructor,k=C.rounding,O=C.precision;if(S.s<0||!T||!T[0]||!S.e&&T[0]==1&&T.length==1)return new C(T&&!T[0]?-1/0:S.s!=1?NaN:T?0:S);if(i==null?(K=!1,p=O):p=i,C.precision=p+=B,t=Qt(T),r=t.charAt(0),Math.abs(s=S.e)<15e14){for(;r<7&&r!=1||r==1&&t.charAt(1)>3;)S=S.times(n),t=Qt(S.d),r=t.charAt(0),P++;s=S.e,r>1?(S=new C("0."+t),s++):S=new C(r+"."+t.slice(1))}else return c=qe(C,p+2,O).times(s+""),S=ue(new C(r+"."+t.slice(1)),p-B).plus(c),C.precision=O,i==null?U(S,O,k,K=!0):S;for(_=S,f=l=S=st(S.minus(1),S.plus(1),p,1),y=U(S.times(S),p,1),e=3;;){if(l=U(l.times(y),p,1),c=f.plus(st(l,new C(e),p,1)),Qt(c.d).slice(0,p)===Qt(f.d).slice(0,p))if(f=f.times(2),s!==0&&(f=f.plus(qe(C,p+2,O).times(s+""))),f=st(f,new C(P),p,1),i==null)if(Ie(f.d,p-B,k,d))C.precision=p+=B,c=l=S=st(_.minus(1),_.plus(1),p,1),y=U(S.times(S),p,1),e=d=1;else return U(f,C.precision=O,k,K=!0);else return C.precision=O,f;f=c,e+=2}}function vr(n){return String(n.s*n.s/0)}function De(n,i){var t,r,e;for((t=i.indexOf("."))>-1&&(i=i.replace(".","")),(r=i.search(/e/i))>0?(t<0&&(t=r),t+=+i.slice(r+1),i=i.substring(0,r)):t<0&&(t=i.length),r=0;i.charCodeAt(r)===48;r++);for(e=i.length;i.charCodeAt(e-1)===48;--e);if(i=i.slice(r,e),i){if(e-=r,n.e=t=t-r-1,n.d=[],r=(t+1)%Q,t<0&&(r+=Q),r<e){for(r&&n.d.push(+i.slice(0,r)),e-=Q;r<e;)n.d.push(+i.slice(r,r+=Q));i=i.slice(r),r=Q-i.length}else r-=e;for(;r--;)i+="0";n.d.push(+i),K&&(n.e>n.constructor.maxE?(n.d=null,n.e=NaN):n.e<n.constructor.minE&&(n.e=0,n.d=[0]))}else n.e=0,n.d=[0];return n}function pn(n,i){var t,r,e,s,l,d,f,c,p;if(i.indexOf("_")>-1){if(i=i.replace(/(\d)_(?=\d)/g,"$1"),_r.test(i))return De(n,i)}else if(i==="Infinity"||i==="NaN")return+i||(n.s=NaN),n.e=NaN,n.d=null,n;if(un.test(i))t=16,i=i.toLowerCase();else if(ln.test(i))t=2;else if(dn.test(i))t=8;else throw Error(de+i);for(s=i.search(/p/i),s>0?(f=+i.slice(s+1),i=i.substring(2,s)):i=i.slice(2),s=i.indexOf("."),l=s>=0,r=n.constructor,l&&(i=i.replace(".",""),d=i.length,s=d-s,e=br(r,new r(t),s,s*2)),c=Re(i,t,Xt),p=c.length-1,s=p;c[s]===0;--s)c.pop();return s<0?new r(n.s*0):(n.e=je(c,p),n.d=c,K=!1,l&&(n=st(n,e,d*4)),f&&(n=n.times(Math.abs(f)<54?Ut(2,f):Ee.pow(2,f))),K=!0,n)}function mn(n,i){var t,r=i.d.length;if(r<3)return i.isZero()?i:ve(n,2,i,i);t=1.4*Math.sqrt(r),t=t>16?16:t|0,i=i.times(1/We(5,t)),i=ve(n,2,i,i);for(var e,s=new n(5),l=new n(16),d=new n(20);t--;)e=i.times(i),i=i.times(s.plus(e.times(l.times(e).minus(d))));return i}function ve(n,i,t,r,e){var s,l,d,f,c=1,p=n.precision,_=Math.ceil(p/Q);for(K=!1,f=t.times(t),d=new n(r);;){if(l=st(d.times(f),new n(i++*i++),p,1),d=e?r.plus(l):r.minus(l),r=st(l.times(f),new n(i++*i++),p,1),l=d.plus(r),l.d[_]!==void 0){for(s=_;l.d[s]===d.d[s]&&s--;);if(s==-1)break}s=d,d=r,r=l,l=s,c++}return K=!0,l.d.length=_+1,l}function We(n,i){for(var t=n;--i;)t*=n;return t}function yr(n,i){var t,r=i.s<0,e=ie(n,n.precision,1),s=e.times(.5);if(i=i.abs(),i.lte(s))return se=r?4:1,i;if(t=i.divToInt(e),t.isZero())se=r?3:2;else{if(i=i.minus(t.times(e)),i.lte(s))return se=ur(t)?r?2:3:r?4:1,i;se=ur(t)?r?1:4:r?3:2}return i.minus(e).abs()}function Ei(n,i,t,r){var e,s,l,d,f,c,p,_,y,P=n.constructor,B=t!==void 0;if(B?($t(t,1,fe),r===void 0?r=P.rounding:$t(r,0,8)):(t=P.precision,r=P.rounding),!n.isFinite())p=vr(n);else{for(p=re(n),l=p.indexOf("."),B?(e=2,i==16?t=t*4-3:i==8&&(t=t*3-2)):e=i,l>=0&&(p=p.replace(".",""),y=new P(1),y.e=p.length-l,y.d=Re(re(y),10,e),y.e=y.d.length),_=Re(p,10,e),s=f=_.length;_[--f]==0;)_.pop();if(!_[0])p=B?"0p+0":"0";else{if(l<0?s--:(n=new P(n),n.d=_,n.e=s,n=st(n,y,t,r,0,e),_=n.d,s=n.e,c=cr),l=_[t],d=e/2,c=c||_[t+1]!==void 0,c=r<4?(l!==void 0||c)&&(r===0||r===(n.s<0?3:2)):l>d||l===d&&(r===4||c||r===6&&_[t-1]&1||r===(n.s<0?8:7)),_.length=t,c)for(;++_[--t]>e-1;)_[t]=0,t||(++s,_.unshift(1));for(f=_.length;!_[f-1];--f);for(l=0,p="";l<f;l++)p+=Ai.charAt(_[l]);if(B){if(f>1)if(i==16||i==8){for(l=i==16?4:3,--f;f%l;f++)p+="0";for(_=Re(p,e,i),f=_.length;!_[f-1];--f);for(l=1,p="1.";l<f;l++)p+=Ai.charAt(_[l])}else p=p.charAt(0)+"."+p.slice(1);p=p+(s<0?"p":"p+")+s}else if(s<0){for(;++s;)p="0"+p;p="0."+p}else if(++s>f)for(s-=f;s--;)p+="0";else s<f&&(p=p.slice(0,s)+"."+p.slice(s))}p=(i==16?"0x":i==2?"0b":i==8?"0o":"")+p}return n.s<0?"-"+p:p}function dr(n,i){if(n.length>i)return n.length=i,!0}function _n(n){return new this(n).abs()}function gn(n){return new this(n).acos()}function bn(n){return new this(n).acosh()}function wn(n,i){return new this(n).plus(i)}function vn(n){return new this(n).asin()}function yn(n){return new this(n).asinh()}function Mn(n){return new this(n).atan()}function Pn(n){return new this(n).atanh()}function An(n,i){n=new this(n),i=new this(i);var t,r=this.precision,e=this.rounding,s=r+4;return!n.s||!i.s?t=new this(NaN):!n.d&&!i.d?(t=ie(this,s,1).times(i.s>0?.25:.75),t.s=n.s):!i.d||n.isZero()?(t=i.s<0?ie(this,r,e):new this(0),t.s=n.s):!n.d||i.isZero()?(t=ie(this,s,1).times(.5),t.s=n.s):i.s<0?(this.precision=s,this.rounding=1,t=this.atan(st(n,i,s,1)),i=ie(this,s,1),this.precision=r,this.rounding=e,t=n.s<0?t.minus(i):t.plus(i)):t=this.atan(st(n,i,s,1)),t}function Bn(n){return new this(n).cbrt()}function Sn(n){return U(n=new this(n),n.e+1,2)}function In(n,i,t){return new this(n).clamp(i,t)}function En(n){if(!n||typeof n!="object")throw Error(Le+"Object expected");var i,t,r,e=n.defaults===!0,s=["precision",1,fe,"rounding",0,8,"toExpNeg",-we,0,"toExpPos",0,we,"maxE",0,we,"minE",-we,0,"modulo",0,9];for(i=0;i<s.length;i+=3)if(t=s[i],e&&(this[t]=Bi[t]),(r=n[t])!==void 0)if(Kt(r)===r&&r>=s[i+1]&&r<=s[i+2])this[t]=r;else throw Error(de+t+": "+r);if(t="crypto",e&&(this[t]=Bi[t]),(r=n[t])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[t]=!0;else throw Error(pr);else this[t]=!1;else throw Error(de+t+": "+r);return this}function On(n){return new this(n).cos()}function xn(n){return new this(n).cosh()}function Mr(n){var i,t,r;function e(s){var l,d,f,c=this;if(!(c instanceof e))return new e(s);if(c.constructor=e,fr(s)){c.s=s.s,K?!s.d||s.e>e.maxE?(c.e=NaN,c.d=null):s.e<e.minE?(c.e=0,c.d=[0]):(c.e=s.e,c.d=s.d.slice()):(c.e=s.e,c.d=s.d?s.d.slice():s.d);return}if(f=typeof s,f==="number"){if(s===0){c.s=1/s<0?-1:1,c.e=0,c.d=[0];return}if(s<0?(s=-s,c.s=-1):c.s=1,s===~~s&&s<1e7){for(l=0,d=s;d>=10;d/=10)l++;K?l>e.maxE?(c.e=NaN,c.d=null):l<e.minE?(c.e=0,c.d=[0]):(c.e=l,c.d=[s]):(c.e=l,c.d=[s]);return}if(s*0!==0){s||(c.s=NaN),c.e=NaN,c.d=null;return}return De(c,s.toString())}if(f==="string")return(d=s.charCodeAt(0))===45?(s=s.slice(1),c.s=-1):(d===43&&(s=s.slice(1)),c.s=1),_r.test(s)?De(c,s):pn(c,s);if(f==="bigint")return s<0?(s=-s,c.s=-1):c.s=1,De(c,s.toString());throw Error(de+s)}if(e.prototype=I,e.ROUND_UP=0,e.ROUND_DOWN=1,e.ROUND_CEIL=2,e.ROUND_FLOOR=3,e.ROUND_HALF_UP=4,e.ROUND_HALF_DOWN=5,e.ROUND_HALF_EVEN=6,e.ROUND_HALF_CEIL=7,e.ROUND_HALF_FLOOR=8,e.EUCLID=9,e.config=e.set=En,e.clone=Mr,e.isDecimal=fr,e.abs=_n,e.acos=gn,e.acosh=bn,e.add=wn,e.asin=vn,e.asinh=yn,e.atan=Mn,e.atanh=Pn,e.atan2=An,e.cbrt=Bn,e.ceil=Sn,e.clamp=In,e.cos=On,e.cosh=xn,e.div=Tn,e.exp=Cn,e.floor=kn,e.hypot=Rn,e.ln=Dn,e.log=Fn,e.log10=qn,e.log2=Nn,e.max=Ln,e.min=jn,e.mod=Wn,e.mul=Zn,e.pow=Un,e.random=Hn,e.round=Qn,e.sign=Kn,e.sin=$n,e.sinh=zn,e.sqrt=Gn,e.sub=Vn,e.sum=Xn,e.tan=Jn,e.tanh=Yn,e.trunc=to,n===void 0&&(n={}),n&&n.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],i=0;i<r.length;)n.hasOwnProperty(t=r[i++])||(n[t]=this[t]);return e.config(n),e}function Tn(n,i){return new this(n).div(i)}function Cn(n){return new this(n).exp()}function kn(n){return U(n=new this(n),n.e+1,3)}function Rn(){var n,i,t=new this(0);for(K=!1,n=0;n<arguments.length;)if(i=new this(arguments[n++]),i.d)t.d&&(t=t.plus(i.times(i)));else{if(i.s)return K=!0,new this(1/0);t=i}return K=!0,t.sqrt()}function fr(n){return n instanceof Ee||n&&n.toStringTag===mr||!1}function Dn(n){return new this(n).ln()}function Fn(n,i){return new this(n).log(i)}function Nn(n){return new this(n).log(2)}function qn(n){return new this(n).log(10)}function Ln(){return wr(this,arguments,-1)}function jn(){return wr(this,arguments,1)}function Wn(n,i){return new this(n).mod(i)}function Zn(n,i){return new this(n).mul(i)}function Un(n,i){return new this(n).pow(i)}function Hn(n){var i,t,r,e,s=0,l=new this(1),d=[];if(n===void 0?n=this.precision:$t(n,1,fe),r=Math.ceil(n/Q),this.crypto)if(crypto.getRandomValues)for(i=crypto.getRandomValues(new Uint32Array(r));s<r;)e=i[s],e>=429e7?i[s]=crypto.getRandomValues(new Uint32Array(1))[0]:d[s++]=e%1e7;else if(crypto.randomBytes){for(i=crypto.randomBytes(r*=4);s<r;)e=i[s]+(i[s+1]<<8)+(i[s+2]<<16)+((i[s+3]&127)<<24),e>=214e7?crypto.randomBytes(4).copy(i,s):(d.push(e%1e7),s+=4);s=r/4}else throw Error(pr);else for(;s<r;)d[s++]=Math.random()*1e7|0;for(r=d[--s],n%=Q,r&&n&&(e=Ut(10,Q-n),d[s]=(r/e|0)*e);d[s]===0;s--)d.pop();if(s<0)t=0,d=[0];else{for(t=-1;d[0]===0;t-=Q)d.shift();for(r=1,e=d[0];e>=10;e/=10)r++;r<Q&&(t-=Q-r)}return l.e=t,l.d=d,l}function Qn(n){return U(n=new this(n),n.e+1,this.rounding)}function Kn(n){return n=new this(n),n.d?n.d[0]?n.s:0*n.s:n.s||NaN}function $n(n){return new this(n).sin()}function zn(n){return new this(n).sinh()}function Gn(n){return new this(n).sqrt()}function Vn(n,i){return new this(n).sub(i)}function Xn(){var n=0,i=arguments,t=new this(i[n]);for(K=!1;t.s&&++n<i.length;)t=t.plus(i[n]);return K=!0,U(t,this.precision,this.rounding)}function Jn(n){return new this(n).tan()}function Yn(n){return new this(n).tanh()}function to(n){return U(n=new this(n),n.e+1,1)}I[Symbol.for("nodejs.util.inspect.custom")]=I.toString;I[Symbol.toStringTag]="Decimal";var Ee=I.constructor=Mr(Bi);Fe=new Ee(Fe);Ne=new Ee(Ne);var j=Ee;var Ze=(r=>(r[r.Spot=0]="Spot",r[r.Curve=1]="Curve",r[r.BidAsk=2]="BidAsk",r))(Ze||{});import{d as $,DETAILS_KEYS as Ue,MathUtil as eo}from"@cetusprotocol/common-sdk";var ce=1e3,To=-443636,Co=443636,he=1e4,Oe=2e3,ye=200,Me=443636n,Oi=1e8,Pr=1e9,Jt=1e4,ko=604800,Ro=1747627200;var nt=Mi(ke());var io=new nt.default(524288),q=64,xi=new nt.default(1).shln(q),Ar=new nt.default(2).pow(new nt.default(128)).sub(new nt.default(1)),F=class n{static splitBinLiquidityInfo(i,t,r){let e=n.getPositionCount(t,r);if(e<=1)return[i];let s=[],l=t;for(let d=0;d<e;d++){let f=Math.min(l+1e3-2,r),c=i.bins.filter(p=>p.bin_id>=l&&p.bin_id<=f);s.push({bins:c,amount_a:c.reduce((p,_)=>$(p).plus(_.amount_a),$(0)).toFixed(0),amount_b:c.reduce((p,_)=>$(p).plus(_.amount_b),$(0)).toFixed(0)}),l=f+1}return s}static processBinsByRate(i,t){let r=[],e=$(0),s=$(0),l=!1;return i.forEach(d=>{let{amount_a:f,amount_b:c,liquidity:p="0"}=d,_=$(t).mul(p).toFixed(0),y=$(f).mul(t),P=$(c).mul(t);e=$(e).plus(y),s=$(s).plus(P),($(y).lt(1)&&$(y).gt(0)||$(P).lt(1)&&$(P).gt(0))&&(l=!0),r.push({bin_id:d.bin_id,amount_a:y.toFixed(0),amount_b:P.toFixed(0),price_per_lamport:d.price_per_lamport,liquidity:_})}),{bins:{bins:r,amount_a:e.toFixed(0),amount_b:s.toFixed(0)},has_invalid_amount:l}}static calculateOutByShare(i,t){let{amount_a:r,amount_b:e,liquidity:s="0"}=i;if(s==="0")return{amount_a:"0",amount_b:"0"};if($(t).gte($(s)))return{amount_a:r,amount_b:e};let l=$(t).div(s).mul(r).toFixed(0,j.ROUND_FLOOR),d=$(t).div(s).mul(e).toFixed(0,j.ROUND_FLOOR);return{amount_a:l,amount_b:d}}static getPositionCount(i,t){let e=$(t).sub(i).add(1).div(1e3);return Number(e.toFixed(0,j.ROUND_UP))}static getLiquidity(i,t,r){return $(r).mul(i).add($(t).mul($(2).pow(q))).toFixed(0)}static getAmountAFromLiquidity(i,t){return $(i).div($(t)).toFixed(0)}static getAmountBFromLiquidity(i){return $(i).div($(2).pow(q)).toFixed(0)}static getAmountsFromLiquidity(i,t,r,e){if($(e).isZero()&&V("LiquiditySupplyIsZero","Liquidity supply is zero"),$(r).gt($(e))&&V("InvalidDeltaLiquidity","Invalid delta liquidity"),$(r).isZero())return["0","0"];let s;$(i).isZero()?s="0":s=$(i).mul($(r)).div($(e)).toFixed(0,j.ROUND_FLOOR);let l;return $(t).isZero()?l="0":l=$(t).mul($(r)).div($(e)).toFixed(0,j.ROUND_FLOOR),[s,l]}static getPriceFromBinId(i,t,r,e){let s=n.getPricePerLamportFromBinId(i,t);return n.getPriceFromLamport(r,e,s).toString()}static getPricePerLamportFromBinId(i,t){let r=new j(t).div(new j(1e4));return new j(1).add(new j(r)).pow(new j(i)).toString()}static getBinIdFromPrice(i,t,r,e,s){let l=n.getPricePerLamport(e,s,i);return n.getBinIdFromLamportPrice(l,t,r)}static getBinIdFromLamportPrice(i,t,r){let e=new j(t).div(new j(1e4)),s=new j(i).log().dividedBy(new j(1).add(e).log());return(r?s.floor():s.ceil()).toNumber()}static getPricePerLamport(i,t,r){return new j(r).mul(new j(10**(t-i))).toString()}static getPriceFromLamport(i,t,r){return new j(r).div(new j(10**(t-i))).toString()}static getReversePrice(i){return new j(1).div(i).toString()}static getQPriceFromId(i,t){let r=new nt.default(t).shln(q).div(new nt.default(1e4)),e=xi.add(r);return n.pow(e,new nt.default(i)).toString()}static getPricePerLamportFromQPrice(i){return eo.fromX64(new nt.default(i)).toString()}static pow(i,t){let r=t.isNeg();if(t.isZero())return xi;if(t=r?t.abs():t,t.gt(io))return new nt.default(0);let e=i,s=xi;return e.gte(s)&&(e=Ar.div(e),r=!r),t.and(new nt.default(1)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new nt.default(2)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new nt.default(4)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new nt.default(8)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new nt.default(16)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new nt.default(32)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new nt.default(64)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new nt.default(128)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new nt.default(256)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new nt.default(512)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new nt.default(1024)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new nt.default(2048)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new nt.default(4096)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new nt.default(8192)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new nt.default(16384)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new nt.default(32768)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new nt.default(65536)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new nt.default(131072)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new nt.default(262144)).isZero()||(s=s.mul(e).shrn(q)),s.isZero()?new nt.default(0):(r&&(s=Ar.div(s)),s)}static binScore(i){let t=BigInt(i)+Me;return(t<0n||t>Me*2n)&&V("InvalidBinId",new Error("Invalid bin ID"),{[Ue.METHOD_NAME]:"binScore",[Ue.REQUEST_PARAMS]:{binId:i}}),t.toString()}static scoreToBinId(i){let t=BigInt(i)-Me;return(t<-Me||t>Me)&&V("InvalidBinId",new Error("Invalid score"),{[Ue.METHOD_NAME]:"scoreToBinId",[Ue.REQUEST_PARAMS]:{score:i}}),Number(t)}static resolveBinPosition(i){let t=BigInt(i),r=t>>4n,e=Number(t&0xfn);return[r.toString(),e]}static findMinMaxBinId(i){let t=1+i/1e4,e=new j("18446744073709551615").log(10).div(new j(t).log(10)).floor(),s=e.neg(),l=e,d=$(1),f=$("340282366920938463463374607431768211455");for(;;){let c=$(n.getQPriceFromId(s.toNumber(),i));if(c.gt(d)&&!c.isZero())break;s=s.add(1)}for(;;){let c=$(n.getQPriceFromId(l.toNumber(),i));if(c.lt(f)&&!c.isZero())break;l=l.sub(1)}return{minBinId:s.toNumber(),maxBinId:l.toNumber()}}static getBinShift(i,t,r){let e=n.getPricePerLamportFromBinId(i,t),s=$(e).mul(1+r).toString(),l=n.getBinIdFromLamportPrice(s,t,!0),d=$(l).sub(i).abs().toFixed(0,j.ROUND_UP);return console.log("getBinShift Options:",{active_id:i,bin_shift:d}),Number(d)}};import{bcs as zt}from"@mysten/sui/bcs";import{blake2b as no}from"blakejs";function Ir(n){try{let i=n.parsedJson;return{id:i.pool_id,bin_step:Number(i.bin_step),coin_type_a:ne(i.coin_type_a,!1),coin_type_b:ne(i.coin_type_b,!1)}}catch(i){return V("ParseError",i,{[pe.METHOD_NAME]:"parseDlmmBasePool",[pe.REQUEST_PARAMS]:n})}}function He(n){try{let i=ki(n),t=Br(n),r=Ci(t),e={bin_step:i.bin_manager.fields.bin_step,bin_manager_handle:i.bin_manager.fields.bins.fields.id.id,size:i.bin_manager.fields.bins.fields.size},s={bin_step:i.position_manager.fields.bin_step,position_index:i.position_manager.fields.position_index,position_handle:i.position_manager.fields.positions.fields.id.id,size:i.position_manager.fields.positions.fields.size},l=i.reward_manager.fields,d=l.rewards.map(_=>{let y=_.fields.current_emission_rate,P=ro.fromX64(new Sr.default(y)),B=Math.floor(P.toNumber()*60*60*24).toString();return{reward_coin:ne(_.fields.reward_coin.fields.name,!1),emissions_per_second:P.toString(),emissions_per_day:B,period_emission_rates:{id:_.fields.period_emission_rates.fields.id.id,size:_.fields.period_emission_rates.fields.size}}}),f={is_public:l.is_public,emergency_reward_pause:l.emergency_reward_pause,vault:{id:l.vault.fields.id.id,size:l.vault.fields.size},rewards:d,last_updated_time:l.last_updated_time},c={volatility_accumulator:i.v_parameters.fields.volatility_accumulator,volatility_reference:i.v_parameters.fields.volatility_reference,index_reference:Ae(BigInt(i.v_parameters.fields.index_reference.fields.bits)),last_update_timestamp:i.v_parameters.fields.last_update_timestamp,bin_step_config:i.v_parameters.fields.bin_step_config.fields},p={id:i.id.id,bin_step:Number(i.bin_step),coin_type_a:ne(r.type_arguments[0],!1),coin_type_b:ne(r.type_arguments[1],!1),pool_type:t,index:Number(i.index),bin_manager:e,variable_parameters:c,active_id:Ae(BigInt(i.active_id.fields.bits)),permissions:i.permissions.fields,balance_a:i.balance_a,balance_b:i.balance_b,base_fee_rate:i.base_fee_rate,protocol_fee_a:i.protocol_fee_a,protocol_fee_b:i.protocol_fee_b,url:i.url,reward_manager:f,position_manager:s};return p.bin_step=p.bin_manager.bin_step,p}catch(i){return console.log("\u{1F680} ~ parseDlmmPool ~ error:",i),V("ParseError",i,{[pe.METHOD_NAME]:"parseDlmmPool",[pe.REQUEST_PARAMS]:n})}}function Ri(n){let i=ki(n),t=Br(n),r=Ci(t);return{id:i.id.id,name:i.name,ref_fee_rate:Ti(i.ref_fee_rate).div(1e4).toNumber(),start_time:Number(i.start_time),end_time:Number(i.end_time),balances:{id:i.balances.fields.id.id,size:i.balances.fields.size},type:r.full_address}}function Di(n){try{let i=ki(n);return{uri:i.uri,index:i.index,id:i.id.id,name:i.name,pool_id:i.pool_id,lower_bin_id:Ae(BigInt(i.lower_bin_id.fields.bits)),upper_bin_id:Ae(BigInt(i.upper_bin_id.fields.bits)),liquidity_shares:i.liquidity_shares,description:i.description,coin_type_a:ne(i.coin_type_a,!1),coin_type_b:ne(i.coin_type_b,!1)}}catch(i){return console.log("\u{1F680} ~ parseDlmmPosition ~ error:",i),V("ParseError",i,{[pe.METHOD_NAME]:"parseDlmmPosition",[pe.REQUEST_PARAMS]:n})}}function ms(n,i,t,r){let e=n.map((d,f)=>{let c=t+f,p=F.getPricePerLamportFromBinId(c,i);if(c===r.bin_id){let{amount_a:P,amount_b:B}=F.calculateOutByShare(r,d);return{bin_id:c,amount_a:P,amount_b:B,liquidity:d,price_per_lamport:p}}if(c<r.bin_id){let P=F.getAmountBFromLiquidity(d);return{bin_id:c,amount_a:"0",amount_b:P,liquidity:d,price_per_lamport:p}}let _=F.getQPriceFromId(c,i),y=F.getAmountAFromLiquidity(d,_);return{bin_id:c,amount_a:y,amount_b:"0",liquidity:d,price_per_lamport:p}}),s=e.reduce((d,f)=>d.add(new j(f.amount_a)),new j(0)).toFixed(0),l=e.reduce((d,f)=>d.add(new j(f.amount_b)),new j(0)).toFixed(0);return{bins:e,amount_a:s,amount_b:l}}function Er(n){try{let i=zt.struct("BinAmount",{id:zt.struct("I32",{bits:zt.u32()}),amount_a:zt.u64(),amount_b:zt.u64(),price:zt.u128(),liquidity_supply:zt.u128(),rewards_growth_global:zt.vector(zt.u128()),fee_a_growth_global:zt.u128(),fee_b_growth_global:zt.u128()});return zt.vector(i).parse(Uint8Array.from(n.results[1].returnValues[0][0])).map(r=>({bin_id:Ae(BigInt(r.id.bits)),amount_a:r.amount_a,amount_b:r.amount_b,liquidity:r.liquidity_supply,price_per_lamport:F.getPricePerLamportFromQPrice(r.price)}))}catch(i){return console.log("\u{1F680} ~ parseBinInfo ~ error:",i),[]}}function Fi(n){try{return{bin_id:Ae(BigInt(n.id.fields.bits)),amount_a:n.amount_a,amount_b:n.amount_b,liquidity:n.liquidity_share,price_per_lamport:F.getPricePerLamportFromQPrice(n.price)}}catch(i){return V("ParseError",i,{[pe.METHOD_NAME]:"parseBinInfo",[pe.REQUEST_PARAMS]:{fields:n}})}}function Or(n){let i={},t=n.events?.filter(r=>r.type.includes("pool::CollectFeeEvent"));for(let r=0;r<t.length;r+=1){let{parsedJson:e}=t[r],s={position_id:e.position,fee_owned_a:e.fee_a,fee_owned_b:e.fee_b};i[e.position]=s}return i}function xr(n){let i={},t=n.events?.filter(r=>r.type.includes("pool::CollectRewardEvent"));for(let r=0;r<t.length;r+=1){let{parsedJson:e}=t[r],s=e.position,l=e.reward,d=e.amount,f={coin_type:ne(l.name,!1),reward_owned:d},c=i[s];c?c.rewards.push(f):c={position_id:s,rewards:[f]},i[s]=c}return i}function Tr(n,i){let t=n.events?.filter(r=>r.type.includes("pool::SwapEvent"));for(let r=0;r<t.length;r+=1){let{parsedJson:e}=t[r],{partner:s,pool:l,amount_in:d,amount_out:f,fee:c,ref_fee:p,bin_swaps:_,from:y,target:P}=e,B=_.map(T=>({bin_id:T.bin_id.bits,in_amount:T.amount_in,out_amount:T.amount_out,fee:T.fee,var_fee_rate:T.var_fee_rate}));return{pool_id:l,a2b:i,in_amount:d,out_amount:f,ref_fee_amount:p,fee_amount:c,bin_swaps:B,partner:s,from_coin_type:ne(y.name,!1),to_coin_type:ne(P.name,!1)}}}function _s(n){switch(n){case 0:return 0;case 1:return 1;case 2:return 2}}var oo=["RemoveLiquidityEvent","SwapEvent","AddLiquidityEvent","ClosePositionEvent"];function Cr(n,i,t,r){let e=[],{timestampMs:s,events:l}=n;return l?.forEach((d,f)=>{let{name:c,address:p}=Ci(d.type);if(oo.includes(c)&&p===t&&r===d.parsedJson.pool){let _={tx:d.id.txDigest,sender:d.sender,type:d.type,block_time:s||"0",index:`${i}_${f}`,parsed_json:d.parsedJson};e.push(_)}}),e}function gs(n,i,t){let r=[],e=0,s=new Date(n*1e3).getTime(),l=new Date().getTime();for(;;){let d=s+e*t;if(d>=l&&r.push(d),e>=i)break;e+=1}return r}function bs(n,i,t,r){let e=[];for(let s=i;s<=t;s+=r){let l=n.findLast(d=>Ti(s).gte(d.time));l?e.push({time:s.toString(),emissions_per_second:l.emissions_per_second,emissions_per_day:l.emissions_per_day,visualized_time:new Date(s*1e3).toLocaleString()}):e.push({emissions_per_day:"0",time:s.toString(),emissions_per_second:"0",visualized_time:new Date(s*1e3).toLocaleString()})}return e}function ws(n){if(n.length===0)return;let i=new Date().getTime()/1e3,t=n.findLast(r=>Ti(i).gte(r.time));return t||n[n.length-1]}function oe(n,i){let t=n.mul(i);if(t.gt(0)&&t.lt(1))throw new _e(`Multiplication ${t} is less than 1`,"AmountTooSmall");return t.floor()}function xe(n){if(n.gt(0)&&n.lt(1))throw new _e(`Multiplication ${n.toString()} is less than 1`,"AmountTooSmall");return n.floor()}function kr(n){switch(n){case 0:return"spot";case 1:return"curve";case 2:return"bid_ask"}}function Rr(n,i,t,r){let e=Buffer.from(n,"utf8"),s=Buffer.from(i,"utf8"),l=s.length,d=0;for(;d<l;){let y=s[d];e=Buffer.concat([e,Buffer.from([y])]),d++}let f=zt.u16().serialize(t).toBytes(),c=zt.u16().serialize(r).toBytes(),p=Buffer.concat([e,f,c]),_=no(p,void 0,32);return`0x${Buffer.from(_).toString("hex")}`}import{d as E}from"@cetusprotocol/common-sdk";var Yt=class n{static toWeight(i){console.log("\u{1F680} ~ WeightUtils ~ toWeight ~ options:",i);let{strategy_type:t,active_id:r,bin_step:e,lower_bin_id:s,upper_bin_id:l,total_amount_a:d,total_amount_b:f,active_bin_of_pool:c}=i,p=r<s||r>l,_=F.getQPriceFromId(r,e),y=E(0),P=E(0),B=E(200);if(t===2?B=E(200):t===1?B=E(2e3):t===0&&(B=E(1)),!p&&c){let it=this.calculateActiveWeights(c.amount_a,c.amount_b,_,B);y=it.active_weight_a,P=it.active_weight_b}r===s&&E(f).isZero()&&(y=E(B).mul(E(2).pow(q*2)).div(E(_)).floor(),P=E(0)),r===l&&E(d).isZero()&&(P=E(B).mul(E(2).pow(q)).floor(),y=E(0)),r>s&&r<l&&(E(d).isZero()&&(P=E(B).mul(E(2).pow(q)).floor(),y=E(0)),E(f).isZero()&&(y=E(B).mul(E(2).pow(q*2)).div(E(_)).floor(),P=E(0)));let S=p?E(0):y,T=p?E(0):P,C=E(2e3).sub(E(200)).floor(),k=r>l?l:r,O=r<s?s:r,x=r>s?k===s?E(0):C.div(E(k-s)).floor():E(0),W=l>r?O===l?E(0):C.div(E(l-O)).floor():E(0),L=s,X=[],tt=[];for(;L<=l;){let it=E(0);if(L<r){let at=k-L;t===0?it=E(1):t===2?it=E(B).add(x.mul(at)).floor():t===1&&(it=E(B).sub(x.mul(at)).floor())}else if(L>r){let at=L-O;t===0?it=E(1):t===2?it=E(B).add(W.mul(at)).floor():t===1&&(it=E(B).sub(W.mul(at)).floor())}else it=B;if(X.push(it),L<r)T=T.add(it.mul(E(2).pow(q))).floor(),tt.push(E(0));else if(L>r){let at=it.mul(E(2).pow(q*2)).div(F.getQPriceFromId(L,e)).floor();tt.push(at),S=S.add(at).floor()}else tt.push(E(0));L+=1}return{...i,total_weight_a:S,total_weight_b:T,active_weight_a:y,active_weight_b:P,weights:X,weight_per_prices:tt}}static toWeightSpotBalanced(i,t){let r=[];for(let e=i;e<=t;e++)r.push({bin_id:e,weight:1});return r}static toWeightDescendingOrder(i,t){let r=[];for(let e=i;e<=t;e++)r.push({bin_id:e,weight:t-e+1});return r}static toWeightAscendingOrder(i,t){let r=[];for(let e=i;e<=t;e++)r.push({bin_id:e,weight:e-i+1});return r}static toWeightCurve(i,t,r){if(r<i)return n.toWeightDescendingOrder(i,t);if(r>t)return n.toWeightAscendingOrder(i,t);let e=2e3,l=e-200,d=r>i?Math.floor(l/(r-i)):0,f=t>r?Math.floor(l/(t-r)):0,c=[];for(let p=i;p<=t;p++)p<r?c.push({bin_id:p,weight:e-(r-p)*d}):p>r?c.push({bin_id:p,weight:e-(p-r)*f}):c.push({bin_id:p,weight:e});return c}static toWeightBidAsk(i,t,r){if(r>t)return n.toWeightDescendingOrder(i,t);if(r<i)return n.toWeightAscendingOrder(i,t);let e=2e3,s=200,l=e-s,d=r>i?Math.floor(l/(r-i)):0,f=t>r?Math.floor(l/(t-r)):0,c=[];for(let p=i;p<=t;p++)p<r?c.push({bin_id:p,weight:s+(r-p)*d}):p>r?c.push({bin_id:p,weight:s+(p-r)*f}):c.push({bin_id:p,weight:s});return c}static toAmountBidSide(i,t,r,e,s=!1){let l=e.filter(f=>f.bin_id<=i).reduce(function(f,c){return s?c.bin_id>i?f:f.add(c.weight):c.bin_id>=i?f:f.add(c.weight)},E(0));if(l.cmp(E(0))!=1)throw Error("Invalid parameters");return{bins:e.map(f=>{let c=F.getPricePerLamportFromBinId(f.bin_id,r);if(!(f.bin_id<=i)||f.bin_id>=i&&!s)return{bin_id:f.bin_id,amount_a:"0",amount_b:"0",price_per_lamport:c,liquidity:"0"};{let _=E(f.weight).div(l),y=oe(E(t),_).toString(),P="0",B=F.getQPriceFromId(f.bin_id,r),S=F.getLiquidity(P,y,B);return{bin_id:f.bin_id,amount_b:y,amount_a:P,price_per_lamport:c,liquidity:S}}}),amount_a:"0",amount_b:t}}static toAmountAskSide(i,t,r,e,s=!1){let l=e.filter(f=>f.bin_id>=i).reduce(function(f,c){if(c.bin_id<=i&&!s)return f;{let p=F.getPricePerLamportFromBinId(c.bin_id,t),_=new j(c.weight).div(p);return f.add(_)}},new j(0));if(l.cmp(new j(0))!=1)throw Error("Invalid parameters");return{bins:e.map(f=>{let c=F.getPricePerLamportFromBinId(f.bin_id,t);if(!(f.bin_id>=i)||f.bin_id<=i&&!s)return{bin_id:f.bin_id,amount_a:"0",amount_b:"0",price_per_lamport:c,liquidity:"0"};{let y=new j(f.weight).div(c).div(l),P=oe(E(r),y).toString(),B="0",S=F.getQPriceFromId(f.bin_id,t),T=F.getLiquidity(P,B,S);return{bin_id:f.bin_id,amount_a:P,amount_b:B,price_per_lamport:c,liquidity:T}}}),amount_a:r,amount_b:"0"}}static toAmountBothSide(i,t,r,e,s,l,d){let f=!E(r).isZero()&&E(e).isZero(),c=E(r).isZero()&&!E(e).isZero();if(i>d[d.length-1].bin_id)return n.toAmountBidSide(i,e,t,d);if(c&&i!==d[d.length-1].bin_id)return n.toAmountBidSide(i,e,t,d,!0);if(i<d[0].bin_id)return n.toAmountAskSide(i,t,r,d);if(f&&i!==d[0].bin_id)return n.toAmountAskSide(i,t,r,d,!0);let p=d.filter(_=>_.bin_id===i);if(p.length===1){let{totalWeightA:_,totalWeightB:y,activeWeightA:P,activeWeightB:B}=n.calculateTotalWeights(t,d,i,p[0],s,l,f?"a":c?"b":void 0),S=new j(r.toString()).div(_),T=new j(e.toString()).div(y),C=d.map(x=>{let W=F.getPricePerLamportFromBinId(x.bin_id,t);if(x.bin_id<i||x.bin_id===i&&c){let ot=oe(T,new j(x.weight)),v="0",o=F.getQPriceFromId(x.bin_id,t),u=F.getLiquidity(v,ot.toString(),o);return{bin_id:x.bin_id,amount_a:"0",amount_b:ot.toString(),price_per_lamport:W,liquidity:u}}if(x.bin_id>i||x.bin_id===i&&f){let ot=new j(x.weight).div(W),v=oe(S,new j(ot)),o="0",u=F.getQPriceFromId(x.bin_id,t),h=F.getLiquidity(v.toString(),o,u);return{bin_id:x.bin_id,amount_a:v.toString(),amount_b:"0",price_per_lamport:W,liquidity:h}}let L=oe(S,P),X=oe(T,B),tt=L.toString(),it=X.toString(),at=F.getQPriceFromId(x.bin_id,t),G=F.getLiquidity(tt,it,at);return{bin_id:x.bin_id,amount_a:tt,amount_b:it,price_per_lamport:W,liquidity:G}}),k=C.reduce((x,W)=>E(x).add(E(W.amount_a)),E(0)).toString(),O=C.reduce((x,W)=>E(x).add(E(W.amount_b)),E(0)).toString();return{bins:C,amount_a:k,amount_b:O}}else{let{totalWeightA:_,totalWeightB:y}=n.calculateTotalWeights(t,d,i),P=new j(r.toString()).div(_),B=new j(e.toString()).div(y),S=d.map(k=>{let O=F.getPricePerLamportFromBinId(k.bin_id,t);if(k.bin_id<i){let x=oe(B,new j(k.weight));return{bin_id:k.bin_id,amount_a:"0",amount_b:x.toString(),price_per_lamport:O}}else{let x=new j(k.weight).div(O),W=oe(P,x);return{bin_id:k.bin_id,amount_a:W.toString(),amount_b:"0",price_per_lamport:O}}}),T=S.reduce((k,O)=>E(k).add(E(O.amount_a)),E(0)).toString(),C=S.reduce((k,O)=>E(k).add(E(O.amount_b)),E(0)).toString();return{bins:S,amount_a:T,amount_b:C}}}static autoFillCoinByWeight(i,t,r,e,s,l,d){if(i>d[d.length-1].bin_id)return n.toAmountBidSide(i,r,t,d);if(i<d[0].bin_id)return n.toAmountAskSide(i,t,r,d);let f=d.filter(P=>P.bin_id===i),{totalWeightA:c,totalWeightB:p}=n.calculateTotalWeights(t,d,i,f.length===1?f[0]:void 0,f.length===1?s:void 0,f.length===1?l:void 0),_=E(0);e?_=c.isZero()?new j(0):new j(r).div(c):_=p.isZero()?new j(0):new j(r).div(p);let y=oe(_,e?p:c).toString();return n.toAmountBothSide(i,t,e?r:y,e?y:r,s,l,d)}static calculateActiveWeights(i,t,r,e){let s=E(r),l=E(i),d=E(t),f=E(0),c=E(0);if(l.isZero()&&d.isZero())f=E(e).mul(E(2).pow(q*2)).div(s.mul(2)).floor(),c=E(e).mul(E(2).pow(q)).div(2).floor();else{if(l.isZero())f=E(0);else{let p=d.mul(E(2).pow(q)).div(l);f=E(e).mul(E(2).pow(q*2)).div(s.add(p)).floor()}if(d.isZero())c=E(0);else{let p=E(2).pow(q).add(s.mul(l).div(d)).floor();c=E(e).mul(E(2).pow(q*2)).div(p).floor()}}return{active_weight_a:f,active_weight_b:c}}static calculateTotalWeights(i,t,r,e,s,l,d){let f=E(F.getPricePerLamportFromBinId(r,i)),c=E(0),p=E(0);if(s&&l&&e&&!d)if(E(s).isZero()&&E(l).isZero())c=new j(e.weight).div(f.mul(new j(2))),p=new j(e.weight).div(new j(2));else{let P=new j(s.toString()),B=new j(l.toString());E(s).isZero()||(c=new j(e.weight).div(f.add(B.div(P)))),E(l).isZero()||(p=new j(e.weight).div(new j(1).add(f.mul(P).div(B))))}let _=c,y=p;return t.forEach(P=>{if((P.bin_id<r||d==="b")&&(y=y.add(new j(P.weight))),P.bin_id>r||d==="a"){let B=F.getPricePerLamportFromBinId(P.bin_id,i),S=new j(P.weight).div(B);_=_.add(S)}}),{totalWeightA:_,totalWeightB:y,activeWeightA:c,activeWeightB:p}}};import{d as Gt}from"@cetusprotocol/common-sdk";var Te=class{static toAmountsByWeights(i){let{total_weight_a:t,total_weight_b:r,weights:e,weight_per_prices:s,total_amount_a:l,total_amount_b:d,active_weight_a:f,active_weight_b:c,lower_bin_id:p,upper_bin_id:_,active_id:y,bin_step:P}=i,B=r.isZero()?Gt(0):Gt(d).mul(Gt(2).pow(q*2)).div(r).floor(),S=t.isZero()?Gt(0):Gt(l).mul(Gt(2).pow(q*2)).div(t).floor(),T=xe(S.mul(f).div(Gt(2).pow(q*2))),C=xe(B.mul(c).div(Gt(2).pow(q*2))),k=_-p+1,O=p,x=0,W=[];for(;x<k;){let X=Gt(0),tt=Gt(0),it=F.getQPriceFromId(O,P);O<y?tt=xe(B.mul(e[x]).div(Gt(2).pow(q))):O>y?X=xe(S.mul(s[x]).div(Gt(2).pow(q*2))):(X=T,tt=C);let at=F.getLiquidity(X.toString(),tt.toString(),it);W.push({bin_id:O,amount_a:X.toString(),amount_b:tt.toString(),price_per_lamport:F.getPricePerLamportFromBinId(O,P),liquidity:at}),O+=1,x+=1}return{bins:W,amount_a:l.toString(),amount_b:d.toString()}}static toAmountsBothSideByStrategy(i,t,r,e,s,l,d,f){let c=Yt.toWeight({strategy_type:d,active_id:i,bin_step:t,lower_bin_id:r,upper_bin_id:e,total_amount_a:s,total_amount_b:l,active_bin_of_pool:f});return this.toAmountsByWeights(c)}static autoFillCoinByStrategy(i,t,r,e,s,l,d,f){switch(d){case 0:{let c=Yt.toWeightSpotBalanced(s,l);return Yt.autoFillCoinByWeight(i,t,r,e,f?.amount_a||"0",f?.amount_b||"0",c)}case 1:{let c=Yt.toWeightCurve(s,l,i);return Yt.autoFillCoinByWeight(i,t,r,e,f?.amount_a||"0",f?.amount_b||"0",c)}case 2:{let c=Yt.toWeightBidAsk(s,l,i);return Yt.autoFillCoinByWeight(i,t,r,e,f?.amount_a||"0",f?.amount_b||"0",c)}}}static autoFillCoinByStrategyV2(i,t,r,e,s,l,d,f){let c=this.autoFillCoinByStrategy(i,t,r,e,s,l,d,f),p=Yt.toWeight({strategy_type:d,active_id:i,bin_step:t,lower_bin_id:s,upper_bin_id:l,total_amount_a:c.amount_a,total_amount_b:c.amount_b,active_bin_of_pool:f});return this.toAmountsByWeights(p)}};import{d as lt}from"@cetusprotocol/common-sdk";var Qe=class n{static getVariableFee(i){let{volatility_accumulator:t,bin_step_config:r}=i,{variable_fee_control:e,bin_step:s}=r;return lt(e).gt(0)?lt(t).mul(s).pow(2).mul(e).add(99999999999).div(1e11).toFixed(0):"0"}static calculateCompositionFee(i,t){let r=lt(i).mul(t);return lt(r).mul(lt(1e9).add(t)).div(1e18).toFixed(0)}static calculateProtocolFee(i,t){return lt(i).mul(t).div(1e4).ceil().toFixed(0)}static getProtocolFees(i,t,r){let e=n.calculateProtocolFee(i,r),s=n.calculateProtocolFee(t,r);return{protocol_fee_a:e,protocol_fee_b:s}}static getCompositionFees(i,t,r){let{bin_step_config:e}=r;if(lt(i.liquidity||"0").eq(lt(0)))return{fees_a:"0",fees_b:"0"};let{bin_step:s,base_factor:l}=e,d=F.getQPriceFromId(i.bin_id,s),f=F.getLiquidity(i.amount_a,i.amount_b,d),c=F.getLiquidity(t.amount_a,t.amount_b,d),p=lt(i.liquidity).mul(c).div(f).toFixed(0),{amount_a:_,amount_b:y}=F.calculateOutByShare({bin_id:i.bin_id,liquidity:lt(i.liquidity).add(p).toFixed(0),amount_a:lt(i.amount_a).add(t.amount_a).toFixed(0),amount_b:lt(i.amount_b).add(t.amount_b).toFixed(0),price_per_lamport:i.price_per_lamport},p),P=lt(s).mul(l).mul(10),B=n.getVariableFee(r),S=lt(P).add(B).toFixed(0);lt(S).gt(1e8)&&(S=1e8.toString());let T="0",C="0";return lt(_).gt(t.amount_a)&&lt(t.amount_b).gt(y)?C=n.calculateCompositionFee(lt(t.amount_b).sub(y).toFixed(0),S):lt(y).gt(t.amount_b)&&lt(t.amount_a).gt(_)&&(T=n.calculateCompositionFee(lt(t.amount_a).sub(_).toFixed(0),S)),{fees_a:T,fees_b:C}}};var Dr=class{static calculateIlm(i){let{curvature:t,initial_price:r,max_price:e,bin_step:s,total_supply:l,pool_share_percentage:d,config:f}=i,{price_curve_points_num:c,liquidity_distribution_num:p,tokens_table_num:_,price_table_num:y}=f;if(d<0||d>100)throw new Error("Pool Share Percentage must be greater than 0 and less than 100.");let P=!1;if(e<r)throw new Error("Maximum Price must be greater or equal to Initial Price.");if(e===r&&t!==0)throw new Error("Curvature must be 0 when Maximum and Initial Price are equal.");if(e!==r&&t===0)throw new Error("Maximum and Initial Price must be equal when Curvature is 0.");e===r&&t===0&&(P=!0);let B=N=>L*Math.pow(N/W,t)+r,S=(N,et)=>{let H=L*Math.pow(W,-t)*Math.pow(N,t+1)/(t+1)+r*N,Y=L*Math.pow(W,-t)*Math.pow(et,t+1)/(t+1)+r*et;return H-Y},T=N=>W*Math.pow((N-r)/L,1/t),C=N=>W*Math.pow(N-r,1/t-1)/(t*Math.pow(L,1/t)),k=N=>Math.pow((N-r)/L,1/t)*W,O=(N,et,H)=>{let Y=et/1e4,Se=Math.log(N)/Math.log(1+Y);return H?Math.floor(Se):Math.ceil(Se)},x=(N,et)=>{let H=et/1e4;return Math.pow(1+H,N)},W=l*d/100,L=e-r,X=[],tt=[],it=O(r,s,!1),at=O(e,s,!1),G=0,ot=it;if(P)X.push(r),tt.push(r*W);else for(;ot<=at;){let N=x(ot,s),et=x(ot+1,s),H=k(et)-k(N);G=G+H,tt.push(H*N),X.push(N),ot++}let v={price_curve:{data:[],min_y:0,max_y:0},liquidity_curve:{data:[],min_y:0,max_y:0},dlmm_bins:{data:[],min_y:0,max_y:0},tokens_table:[],price_table:[],initial_fdv:r*l,final_fdv:e*l,usdc_in_pool:0};var o=L/100;let u=[],h=0,m=0;for(let N=0;N<c;N++){let et=N*W/(c-1),H=P?e:B(et);h=h<H?h:H,m=m>H?m:H,u.push({x:et,y:H})}v.price_curve={data:u,min_y:h,max_y:m};let b=[],M=0,A=0;if(P)M=0,A=W,b=[{x:r,y:0},{x:r,y:W/2},{x:r,y:W}];else for(let N=0;N<p;N++){let et=r+N*o,H=C(et);b.push({x:et,y:H}),M=M<H?M:H,A=A>H?A:H}v.liquidity_curve={data:b,min_y:M,max_y:A};let g=[],a=0,w=0;X.forEach((N,et)=>{let H=N,Y=tt[et];g.push({x:H,y:Y}),a=a<Y?a:Y,w=w>Y?w:Y}),v.dlmm_bins={data:g,min_y:a,max_y:w};let R=[],D=0,Z=W/_;for(;D<=W;){let N=B(D),et=D,H=S(et,0);R.push({withdrawn:et,price:N,usdc_in_pool:H}),D=D+Z}v.tokens_table=R;let z=Math.floor(L*1e10)/1e11,J=[];if(P)J.push({withdrawn:W,price:r,usdc_in_pool:W*r});else{let N=0,et=r;for(;N<=y;){let H=T(et),Y=S(H,0);J.push({withdrawn:H,price:et,usdc_in_pool:Y}),et=et+z,N=N+1}}return v.price_table=J,v.usdc_in_pool=J[J.length-1].usdc_in_pool,v}};import{SuiClient as fo}from"@mysten/sui/client";import{normalizeSuiAddress as jr}from"@mysten/sui/utils";import{bcs as $e}from"@mysten/sui/bcs";var ze=class{constructor(i){this._sdk=i}get sdk(){return this._sdk}async getPoolAddress(i,t,r,e){try{let s=Rr(i,t,r,e),{dlmm_pool:l}=this._sdk.sdkOptions,{pools_id:d}=Lr(l),f=await this._sdk.FullClient.getDynamicFieldObject({parentId:d,name:{type:"0x2::object::ID",value:s}});return qr(f).value.fields.value.fields.pool_id}catch(s){return V("FetchError",s,{[te.METHOD_NAME]:"getPoolAddress",[te.REQUEST_PARAMS]:{coin_type_a:i,coin_type_b:t,bin_step:r,base_factor:e}})}}async getBasePoolList(i="all",t=!1){let{dlmm_pool:r}=this._sdk.sdkOptions,e={data:[],has_next_page:!1},s=i==="all",l=`${r.package_id}_getBasePoolList`;if(s){let d=this._sdk.getCache(l,t);if(d&&d.length>0)return e.data.push(...d),e}try{let d=`${r.package_id}::registry::CreatePoolEvent`,f=await this._sdk.FullClient.queryEventsByPage({MoveEventType:d},i);e.has_next_page=f.has_next_page,e.next_cursor=f.next_cursor,f.data.forEach(c=>{let p=Ir(c);e.data.push(p)}),s&&this._sdk.updateCache(`${r.package_id}_getPoolImmutables`,e.data)}catch(d){return V("FetchError",d,{[te.METHOD_NAME]:"getBasePoolList"})}return e}async getPools(i="all",t=!1){let r={data:[],has_next_page:!1},e=await this.getBasePoolList(i,t);if(e.data.length===0)return r;try{let s=await this._sdk.FullClient.batchGetObjects(e.data.map(l=>l.id),{showContent:!0,showType:!0});r.has_next_page=e.has_next_page,r.next_cursor=e.next_cursor;for(let l of s){let d=He(l),f=`${d.id}_getDlmmPool`;this._sdk.updateCache(f,d),r.data.push(d)}}catch(s){return V("FetchError",s,{[te.METHOD_NAME]:"getPools"})}return r}async getBinInfo(i,t,r,e=!0){try{let s=`${i}_getBinInfo_${t}`,l=this._sdk.getCache(s,e);if(l!==void 0)return l;let d=F.binScore(t),[f,c]=F.resolveBinPosition(d),_=(await this._sdk.FullClient.getDynamicFieldObject({parentId:i,name:{type:"u64",value:f}})).data.content.fields.value.fields.value.fields.group.fields.bins[c].fields,y=Fi(_);return this._sdk.updateCache(s,y),y}catch{return{bin_id:t,amount_a:"0",amount_b:"0",liquidity:"0",price_per_lamport:F.getPricePerLamportFromBinId(t,r)}}}async getBinInfoList(i){let t=[],r=i.map(s=>{let{bin_manager_handle:l,bin_id:d,bin_step:f}=s,c=F.binScore(d),[p,_]=F.resolveBinPosition(c),y=lo(l,p,"u64","u64");return{groupIndex:p,offsetInGroup:_,bin_id:d,bin_step:f,bin_manager_handle:l,dynamic_field_id:y}});return(await this._sdk.FullClient.batchGetObjects(r.map(s=>s.dynamic_field_id),{showContent:!0,showType:!0})).forEach((s,l)=>{let{offsetInGroup:d,bin_manager_handle:f,bin_step:c,bin_id:p}=r[l];try{let y=qr(s).value.fields.value.fields.group.fields.bins[d].fields,P=Fi(y);t.push({...P,bin_manager_handle:f,bin_step:c})}catch{t.push({bin_id:p,amount_a:"0",amount_b:"0",liquidity:"0",price_per_lamport:F.getPricePerLamportFromBinId(p,c),bin_manager_handle:f,bin_step:c})}}),t}async getTotalFeeRate(i){let{dlmm_pool:t}=this._sdk.sdkOptions,{pool_id:r,coin_type_a:e,coin_type_b:s}=i,l=new Ke;l.moveCall({target:`${t.published_at}::pool::get_total_fee_rate`,arguments:[l.object(r)],typeArguments:[e,s]});let d=await this._sdk.FullClient.devInspectTransactionBlock({transactionBlock:l,sender:jr("0x0")});return $e.struct("FeeRate",{base_fee_rate:$e.u64(),var_fee_rate:$e.u64(),total_fee_rate:$e.u64()}).parse(Uint8Array.from(d.results[0].returnValues[0][0]))}async getPoolBinInfo(i){let{dlmm_pool:t}=this._sdk.sdkOptions,{pool_id:r,coin_type_a:e,coin_type_b:s}=i,l=1e3,d=[],f,c=!0;for(;c;){let p=new Ke,_;f!==void 0?_=p.moveCall({target:"0x1::option::some",arguments:[p.pure.u32(Number(Fr(BigInt(f))))],typeArguments:["u32"]}):_=p.moveCall({target:"0x1::option::none",typeArguments:["u32"]}),p.moveCall({target:`${t.published_at}::pool::fetch_bins`,arguments:[p.object(r),_,p.pure.u64(l)],typeArguments:[e,s]});let y=await this._sdk.FullClient.devInspectTransactionBlock({transactionBlock:p,sender:jr("0x0")}),P=Er(y);d.push(...P),f=P.length>0?P[P.length-1].bin_id+1:void 0,c=P.length===l}return d.sort((p,_)=>p.bin_id-_.bin_id)}async getPoolTransactionList({pool_id:i,pagination_args:t,order:r="descending",full_rpc_url:e}){let{FullClient:s,sdkOptions:l}=this._sdk,d;e?d=ao(new fo({url:e})):d=s;let f={data:[],has_next_page:!1},c=50,p=t,_=t.limit||10;do{let y=await d.queryTransactionBlocksByPage({ChangedObject:i},{...p,limit:50},r);y.data.forEach((P,B)=>{let S=Cr(P,B,l.dlmm_pool.package_id,i);f.data=[...f.data,...S]}),f.has_next_page=y.has_next_page,f.next_cursor=y.next_cursor,p.cursor=y.next_cursor}while(f.data.length<_&&f.has_next_page);return f.data.length>_&&(f.data=f.data.slice(0,_),f.has_next_page=!0),f.data.length>0&&(f.next_cursor=f.data[f.data.length-1].tx),f}async getRangeBinInfo(i,t,r,e){let s=[];for(let l=t;l<=r;l++){let d=await Promise.all([this.getBinInfo(i,l,e)]);s.push(...d)}return s}async getAssignPoolList(i){if(i.length===0)return[];let t=[];try{let r=await this._sdk.FullClient.batchGetObjects(i,{showContent:!0,showType:!0});for(let e of r){let s=He(e),l=`${s.id}_getDlmmPool`;this._sdk.updateCache(l,s),t.push(s)}}catch(r){return V("FetchError",r,{[te.METHOD_NAME]:"getAssignPoolList"})}return t}async getPool(i,t=!0){try{let r=`${i}_getDlmmPool`,e=this._sdk.getCache(r,t);if(e!==void 0)return e;let s=await this._sdk.FullClient.getObject({id:i,options:{showType:!0,showContent:!0}}),l=He(s);return this._sdk.updateCache(r,l),l}catch(r){return V("FetchError",r,{[te.METHOD_NAME]:"getPool",[te.REQUEST_PARAMS]:i})}}async createPoolAndAddWithPricePayload(i){let{bin_step:t,url:r,coin_type_a:e,coin_type_b:s,bin_infos:l,price_base_coin:d,price:f,lower_price:c,upper_price:p,decimals_a:_,decimals_b:y,strategy_type:P,use_bin_infos:B,base_factor:S,pool_id:T}=i,C,k,O,x=l;if(d==="coin_a")C=F.getBinIdFromPrice(c,t,!1,_,y),k=F.getBinIdFromPrice(p,t,!0,_,y),O=F.getBinIdFromPrice(f,t,!0,_,y);else{C=F.getBinIdFromPrice(Ni(1).div(p).toString(),t,!1,_,y),k=F.getBinIdFromPrice(Ni(1).div(c).toString(),t,!0,_,y),O=F.getBinIdFromPrice(Ni(1).div(f).toString(),t,!1,_,y);let X={pool_id:T,amount_a:l.amount_b,amount_b:l.amount_a,active_id:O,bin_step:t,lower_bin_id:C,upper_bin_id:k,active_bin_of_pool:void 0,strategy_type:i.strategy_type};x=await this.sdk.Position.calculateAddLiquidityInfo(X)}let L={bin_step:t,url:r,coin_type_a:e,coin_type_b:s,bin_infos:x,lower_bin_id:C,upper_bin_id:k,active_id:O,strategy_type:P,use_bin_infos:B,base_factor:S};return this.createPoolAndAddLiquidityPayload(L)}createPoolPayload(i,t){let{dlmm_pool:r}=this._sdk.sdkOptions,{bin_step:e,base_factor:s,url:l,coin_type_a:d,coin_type_b:f,active_id:c}=i;t=t||new Ke;let{registry_id:p,global_config_id:_,versioned_id:y}=Lr(r),[P,B]=t.moveCall({target:`${r.published_at}::registry::create_pool_v2`,arguments:[t.object(p),t.pure.u16(e),t.pure.u16(s),t.pure.u32(Number(Fr(BigInt(c)))),t.pure.string(l||""),t.object(_),t.object(y),t.object(so)],typeArguments:[d,f]});return t.moveCall({target:`${r.published_at}::registry::destroy_receipt`,arguments:[t.object(P),B,t.object(y)],typeArguments:[d,f]}),B}createPoolAndAddLiquidityPayload(i){let{bin_step:t,base_factor:r,url:e,active_id:s,coin_type_a:l,coin_type_b:d,bin_infos:f,lower_bin_id:c,upper_bin_id:p,strategy_type:_,use_bin_infos:y}=i,P=new Ke;uo(Nr(l,!1),Nr(d,!1))&&V("InvalidCoinTypeSequence",new Error("invalid coin type sequence"),{[te.METHOD_NAME]:"createPoolAndAddLiquidityPayload",[te.REQUEST_PARAMS]:i});let B=p-c+1;B>1e3&&V("InvalidBinWidth",new Error("Width is too large"),{[te.METHOD_NAME]:"openPosition",[te.REQUEST_PARAMS]:i}),console.log("\u{1F680} ~ createPoolAndAddLiquidityPayload ~ option:",{...i,width:B});let T={pool_id:this.createPoolPayload({active_id:s,bin_step:t,base_factor:r,coin_type_a:l,coin_type_b:d},P),bin_infos:f,coin_type_a:l,coin_type_b:d,lower_bin_id:c,upper_bin_id:p,active_id:s,strategy_type:_,use_bin_infos:y,max_price_slippage:0,bin_step:t};return this.sdk.Position.addLiquidityPayload(T,P),P}};import{FullRpcUrlTestnet as co,GraphRpcUrlTestnet as ho}from"@cetusprotocol/common-sdk";var Wr={env:"testnet",full_rpc_url:co,graph_rpc_url:ho,dlmm_pool:{package_id:"0xb382224d12558da5f87624765065a8c7e8f5c899d0ee890610e2bb4e8c686be9",published_at:"0x1cdac9c678c5ec89c80409db8865c9c3f8e6207dfd988fb4ddd11e2806db0bf9",version:1,config:{registry_id:"0xdc91c4f094557b9d2a35fc6159ef32649a54c4aa9350860bf0d4b52b5f0a3990",pools_id:"0xb518b1de84a1ba1ab6c9a2d71fcdf382ef36045a4660497b3d77fb0a6df7709e",global_config_id:"0xe84ebca8d61cdd9312cec3787204d0ee1063d424a81dcda62cfb8b1887041a9f",versioned_id:"0xf8478d6dc081bc266229f25ac9c31a96b5e99ecbd82222e883368dda95829065",admin_cap_id:"0x273dbda2a1d62460a01a07831aec0fa8191a41341d634fb43f15acdb627edbce",partners_id:"0xd7ac594ed2e7756f0d4a98503dd970f314f2619a10c3613c705253a155cc9fea"}},dlmm_router:{package_id:"0xbc76d04e910452518efd5fd63d5fffe77c24855063c9cdb5501e06896bc34908",published_at:"0xe122ffbcfe5091398ba15a60e654e6589fd586b3865d5b4118292754f8cde301",version:1},faucet:{package_id:"0x14a71d857b34677a7d57e0feb303df1adb515a37780645ab763d42ce8d1a5e48",published_at:"0x14a71d857b34677a7d57e0feb303df1adb515a37780645ab763d42ce8d1a5e48",version:1}};import{asUintN as ae,CLOCK_ADDRESS as me,CoinAssist as ee,d as rt,DETAILS_KEYS as Vt,getPackagerConfigs as ge}from"@cetusprotocol/common-sdk";import{Transaction as be}from"@mysten/sui/transactions";import{normalizeSuiAddress as po}from"@mysten/sui/utils";var Ge=class{constructor(i){this._sdk=i}get sdk(){return this._sdk}buildPositionType(){return`${this._sdk.sdkOptions.dlmm_pool.package_id}::position::Position`}async getOwnerPositionList(i){let t=[];try{(await this._sdk.FullClient.getOwnedObjectsByPage(i,{options:{showType:!0,showContent:!0,showOwner:!0},filter:{StructType:this.buildPositionType()}})).data.forEach(e=>{t.push(Di(e))})}catch(r){console.log("\u{1F680} ~ PositionModule ~ getOwnerPositionList ~ error:",r),V("GetObjectError",r,{[Vt.METHOD_NAME]:"getOwnerPositionList",[Vt.REQUEST_PARAMS]:i})}return t}async getPosition(i){try{let t=await this._sdk.FullClient.getObject({id:i,options:{showType:!0,showContent:!0,showOwner:!0}});return Di(t)}catch(t){return console.log("\u{1F680} ~ PositionModule ~ getPosition ~ error:",t),V("GetObjectError",t,{[Vt.METHOD_NAME]:"getPosition",[Vt.REQUEST_PARAMS]:i})}}collectFeePayload(i,t){let{pool_id:r,position_id:e,coin_type_a:s,coin_type_b:l}=i,{dlmm_pool:d}=this.sdk.sdkOptions,{versioned_id:f,global_config_id:c}=ge(d);t=t||new be;let[p,_]=t.moveCall({target:`${d.published_at}::pool::collect_position_fee`,arguments:[t.object(r),t.object(e),t.object(c),t.object(f)],typeArguments:[s,l]}),y=ee.fromBalance(p,s,t),P=ee.fromBalance(_,l,t);return t.transferObjects([y,P],this.sdk.getSenderAddress()),t}updatePositionFeeAndRewards(i,t){let{dlmm_pool:r}=this.sdk.sdkOptions,{versioned_id:e}=ge(r),{pool_id:s,position_id:l,coin_type_a:d,coin_type_b:f}=i;return t.moveCall({target:`${r.published_at}::pool::update_position_fee_and_rewards`,arguments:[t.object(s),t.pure.id(l),t.object(e),t.object(me)],typeArguments:[d,f]}),t}collectRewardPayload(i,t){let{dlmm_pool:r}=this.sdk.sdkOptions,{versioned_id:e,global_config_id:s}=ge(r);return t=t||new be,i.forEach(l=>{let{pool_id:d,position_id:f,reward_coins:c,coin_type_a:p,coin_type_b:_}=l;c.forEach(y=>{let P=t.moveCall({target:`${r.published_at}::pool::collect_position_reward`,arguments:[t.object(d),t.object(f),t.object(s),t.object(e)],typeArguments:[p,_,y]}),B=ee.fromBalance(P,y,t);t.transferObjects([B],this.sdk.getSenderAddress())})}),t}collectRewardAndFeePayload(i,t){return t=t||new be,i.forEach(r=>{let{pool_id:e,position_id:s,reward_coins:l,coin_type_a:d,coin_type_b:f}=r;this.updatePositionFeeAndRewards({pool_id:e,position_id:s,coin_type_a:d,coin_type_b:f},t),this.collectFeePayload({pool_id:e,position_id:s,coin_type_a:d,coin_type_b:f},t),this.collectRewardPayload([{pool_id:e,position_id:s,reward_coins:l,coin_type_a:d,coin_type_b:f}],t)}),t}validateActiveIdSlippage(i,t){let{pool_id:r,active_id:e,max_price_slippage:s,bin_step:l,coin_type_a:d,coin_type_b:f}=i,{dlmm_router:c}=this.sdk.sdkOptions,p=F.getBinShift(e,l,s),_=Number(ae(BigInt(e)));return t.moveCall({target:`${c.published_at}::utils::validate_active_id_slippage`,arguments:[typeof r=="string"?t.object(r):r,t.pure.u32(Number(_)),t.pure.u32(Number(p))],typeArguments:[d,f]}),t}closePositionPayload(i,t){let{pool_id:r,position_id:e,reward_coins:s,coin_type_a:l,coin_type_b:d}=i,{dlmm_pool:f}=this.sdk.sdkOptions,{versioned_id:c,global_config_id:p}=ge(f);t=t||new be,this.updatePositionFeeAndRewards({pool_id:r,position_id:e,coin_type_a:l,coin_type_b:d},t),this.collectRewardPayload([{pool_id:r,position_id:e,reward_coins:s,coin_type_a:l,coin_type_b:d}],t);let[_,y,P]=t.moveCall({target:`${f.published_at}::pool::close_position`,arguments:[t.object(r),t.object(e),t.object(p),t.object(c),t.object(me)],typeArguments:[l,d]}),B=ee.fromBalance(y,l,t),S=ee.fromBalance(P,d,t);return t.moveCall({target:`${f.published_at}::pool::destroy_close_position_cert`,arguments:[_,t.object(c)],typeArguments:[]}),t.transferObjects([B,S],this.sdk.getSenderAddress()),t}async getActiveBinIfInRange(i,t,r,e,s,l=!1){if(e<=r&&e>=t)return await this._sdk.Pool.getBinInfo(i,e,s,l)}calculateRemoveLiquidityInfo(i){let{bins:t,active_id:r,coin_amount:e}=i,s="fix_amount_a"in i,l=t.filter(y=>y.bin_id<r),d=t.filter(y=>y.bin_id>r),f=rt(0),c=rt(0),p=[];if(s){p=[...t];let{fix_amount_a:y}=i,P=t.find(T=>T.bin_id===r),B=d.reduce((T,C)=>rt(T).plus(C.amount_a),rt(0)).add(P?.amount_a||"0"),S=l.reduce((T,C)=>rt(T).plus(C.amount_b),rt(0)).add(P?.amount_b||"0");f=y?B:S,c=rt(e).gte(f)?rt(1):rt(e).div(f)}else{let{is_only_a:y}=i;p=y?d:l,f=p.reduce((P,B)=>rt(P).plus(y?B.amount_a:B.amount_b),rt(0)),c=rt(e).gte(f)?rt(1):rt(e).div(f)}if(rt(f).isZero())return V("InsufficientLiquidity",new Error("Insufficient liquidity"),{[Vt.METHOD_NAME]:"calculateRemoveLiquidityResult",[Vt.REQUEST_PARAMS]:i});let _=F.processBinsByRate([...p],c.toFixed());if(_.has_invalid_amount){let y=rt(e),P=[],B=s?i.fix_amount_a:i.is_only_a;for(let S of p){if(y.lte(0))break;let T=B?S.amount_a:S.amount_b,C=B?S.amount_b:S.amount_a,k=rt(rt(y).div(T).toFixed(9,j.ROUND_UP));k=k.gt(1)?rt(1):k;let O=rt(T).mul(k);y=y.minus(O);let x=rt(C).mul(k),W=rt(S.liquidity).mul(k);P.push({...S,amount_a:B?O.toFixed(0):x.toFixed(0),amount_b:B?x.toFixed(0):O.toFixed(0),liquidity:W.toFixed(0)})}return{bins:P,amount_a:P.reduce((S,T)=>rt(S).plus(T.amount_a),rt(0)).toFixed(0),amount_b:P.reduce((S,T)=>rt(S).plus(T.amount_b),rt(0)).toFixed(0)}}return _.bins}async calculateAddLiquidityInfo(i){let t="fix_amount_a"in i,{active_id:r,bin_step:e,lower_bin_id:s,upper_bin_id:l,active_bin_of_pool:d,strategy_type:f,pool_id:c}=i,p;if(t){let{coin_amount:_,fix_amount_a:y}=i;p=Te.autoFillCoinByStrategyV2(r,e,_,y,s,l,f,d)}else p=Te.toAmountsBothSideByStrategy(r,e,s,l,i.amount_a,i.amount_b,f,d);if(d&&c){let _=p.bins.findIndex(y=>y.bin_id===r);if(_!==-1){let y=await this._sdk.Pool.getPool(c,!1);if(y){let{fees_a:P,fees_b:B}=Qe.getCompositionFees(d,p.bins[_],y.variable_parameters),S=p.bins[_];S.amount_a=rt(S.amount_a).sub(P).toFixed(0),S.amount_b=rt(S.amount_b).sub(B).toFixed(0),p.bins[_]=S,console.log("\u{1F680} ~ PositionModule ~ calculateAddLiquidityInfo ~ fees_a:",P),console.log("\u{1F680} ~ PositionModule ~ calculateAddLiquidityInfo ~ fees_b:",B)}}}return p}removeLiquidityPayload(i){let{pool_id:t,position_id:r,bin_infos:e,reward_coins:s,slippage:l,coin_type_a:d,coin_type_b:f,active_id:c,collect_fee:p,bin_step:_,remove_percent:y}=i,{dlmm_pool:P}=this.sdk.sdkOptions,{bins:B}=e,S=new be;(p||s.length>0)&&this.updatePositionFeeAndRewards({pool_id:t,position_id:r,coin_type_a:d,coin_type_b:f},S),p&&this.collectFeePayload({pool_id:t,position_id:r,coin_type_a:d,coin_type_b:f},S),this.collectRewardPayload([{pool_id:t,position_id:r,reward_coins:s,coin_type_a:d,coin_type_b:f}],S);let{versioned_id:T,global_config_id:C}=ge(P);if(y){let k=ae(BigInt(B[0].bin_id)),O=ae(BigInt(B[B.length-1].bin_id)),x=Number(rt(y).mul(1e4).toFixed(0)),[W,L]=S.moveCall({target:`${P.published_at}::pool::remove_liquidity_by_percent`,arguments:[S.object(t),S.object(r),S.pure.u32(Number(k)),S.pure.u32(Number(O)),S.pure.u16(x),S.object(C),S.object(T),S.object(me)],typeArguments:[d,f]}),X=ee.fromBalance(W,d,S),tt=ee.fromBalance(L,f,S);S.transferObjects([X,tt],this.sdk.getSenderAddress())}else{let k=S.pure.vector("u32",B.map(tt=>Number(ae(BigInt(tt.bin_id))))),O=S.pure.vector("u128",B.map(tt=>tt.liquidity)),[x,W]=S.moveCall({target:`${P.published_at}::pool::remove_liquidity`,arguments:[S.object(t),S.object(r),k,O,S.object(C),S.object(T),S.object(me)],typeArguments:[d,f]}),L=ee.fromBalance(x,d,S),X=ee.fromBalance(W,f,S);S.transferObjects([L,X],this.sdk.getSenderAddress())}return this.validateActiveIdSlippage({pool_id:t,active_id:c,max_price_slippage:l,bin_step:_,coin_type_a:d,coin_type_b:f},S),S}async addLiquidityWithPricePayload(i){let{pool_id:t,bin_infos:r,coin_type_a:e,coin_type_b:s,price_base_coin:l,price:d,lower_price:f,upper_price:c,bin_step:p,strategy_type:_,active_bin_of_pool:y,decimals_a:P,decimals_b:B,use_bin_infos:S,max_price_slippage:T}=i,C,k,O,x=r;if(l==="coin_a")C=F.getBinIdFromPrice(f,p,!1,P,B),k=F.getBinIdFromPrice(c,p,!0,P,B),O=F.getBinIdFromPrice(d,p,!0,P,B);else{C=F.getBinIdFromPrice(rt(1).div(c).toString(),p,!1,P,B),k=F.getBinIdFromPrice(rt(1).div(f).toString(),p,!0,P,B),O=F.getBinIdFromPrice(rt(1).div(d).toString(),p,!1,P,B);let X={amount_a:r.amount_b,amount_b:r.amount_a,active_id:O,bin_step:p,lower_bin_id:C,upper_bin_id:k,active_bin_of_pool:y,strategy_type:_};x=await this.sdk.Position.calculateAddLiquidityInfo(X)}let L={pool_id:t,active_id:O,bin_infos:x,coin_type_a:e,coin_type_b:s,lower_bin_id:C,upper_bin_id:k,strategy_type:_,use_bin_infos:S,max_price_slippage:T,bin_step:p};return this.addLiquidityPayload(L)}addLiquidityPayload(i,t){let{pool_id:r,bin_infos:e,coin_type_a:s,coin_type_b:l,active_id:d,strategy_type:f,max_price_slippage:c,bin_step:p,use_bin_infos:_=!1}=i;t=t||new be;let y="lower_bin_id"in i,P=[];if(y){let B=F.splitBinLiquidityInfo(e,i.lower_bin_id,i.upper_bin_id);P.push(...B)}else{let B=i.position_id;P.push(e),(i.collect_fee||i.reward_coins.length>0)&&this.updatePositionFeeAndRewards({pool_id:r,position_id:B,coin_type_a:s,coin_type_b:l},t),i.collect_fee&&this.collectFeePayload({pool_id:r,position_id:B,coin_type_a:s,coin_type_b:l},t),i.reward_coins.length>0&&this.collectRewardPayload([{pool_id:r,position_id:B,reward_coins:i.reward_coins,coin_type_a:s,coin_type_b:l}],t)}return P.forEach((B,S)=>{console.log("\u{1F680} ~ PositionModule ~ addLiquidityPayload ~ liquidity_bin:",S,B);let{amount_a:T,amount_b:C,bins:k}=B,O=ee.buildCoinWithBalance(BigInt(T),s,t),x=ee.buildCoinWithBalance(BigInt(C),l,t);_?this.addLiquidityInternal({pool_id:r,coin_type_a:s,coin_type_b:l,active_id:d,liquidity_bin:B,tx:t,coin_a_obj_id:O,coin_b_obj_id:x,position_id:y?void 0:i.position_id,max_price_slippage:c,bin_step:p}):this.addLiquidityStrategyInternal({pool_id:r,coin_type_a:s,coin_type_b:l,active_id:d,liquidity_bin:B,tx:t,max_price_slippage:c,bin_step:p,coin_a_obj_id:O,coin_b_obj_id:x,strategy_type:f,position_id:y?void 0:i.position_id})}),t}addLiquidityStrategyInternal(i){let{max_price_slippage:t,bin_step:r,position_id:e,pool_id:s,coin_type_a:l,coin_type_b:d,active_id:f,liquidity_bin:c,tx:p,coin_a_obj_id:_,coin_b_obj_id:y,strategy_type:P}=i,{dlmm_pool:B,dlmm_router:S}=this.sdk.sdkOptions,{versioned_id:T,global_config_id:C}=ge(B),{bins:k,amount_a:O,amount_b:x}=c,W=e,L=k[0].bin_id,X=k[k.length-1].bin_id,tt=ae(BigInt(L)),it=Number(ae(BigInt(f))),at=F.getBinShift(f,r,t),G=kr(P);if(e===void 0){let ot=X-L+1;ot>1e3&&V("InvalidBinWidth",new Error("Width is too large"),{[Vt.METHOD_NAME]:"openPosition"}),W=p.moveCall({target:`${S.published_at}::${G}::open_position`,arguments:[typeof s=="string"?p.object(s):s,_,y,p.pure.u64(O),p.pure.u64(x),p.pure.u32(Number(tt)),p.pure.u16(Number(ot)),p.pure.u32(Number(it)),p.pure.u32(Number(at)),p.object(C),p.object(T),p.object(me)],typeArguments:[l,d]})}else{let ot=k.filter(u=>u.amount_a!=="0"||u.amount_b!=="0");if(ot.length===0)return V("InvalidParams",new Error("No bins to add liquidity"),{[Vt.METHOD_NAME]:"addLiquidityStrategyInternal",[Vt.REQUEST_PARAMS]:i});let v=ae(BigInt(ot[0].bin_id)),o=ae(BigInt(ot[ot.length-1].bin_id));p.moveCall({target:`${S.published_at}::${G}::add_liquidity`,arguments:[typeof s=="string"?p.object(s):s,p.object(e),_,y,p.pure.u64(O),p.pure.u64(x),p.pure.u32(Number(v)),p.pure.u32(Number(o)),p.pure.u32(Number(it)),p.pure.u32(Number(at)),p.object(C),p.object(T),p.object(me)],typeArguments:[l,d]})}return W?p.transferObjects([W,_,y],this.sdk.getSenderAddress()):p.transferObjects([_,y],this.sdk.getSenderAddress()),p}addLiquidityInternal(i){let{position_id:t,pool_id:r,coin_type_a:e,coin_type_b:s,active_id:l,liquidity_bin:d,tx:f,coin_a_obj_id:c,coin_b_obj_id:p,max_price_slippage:_,bin_step:y}=i,{bins:P}=d,{dlmm_pool:B,dlmm_router:S}=this.sdk.sdkOptions,{versioned_id:T,global_config_id:C}=ge(B),k=f.pure.vector("u64",P.map(X=>X.amount_a)),O=f.pure.vector("u64",P.map(X=>X.amount_b)),x=f.makeMoveVec({elements:P.map(X=>f.pure.u32(Number(ae(BigInt(X.bin_id))))),type:"u32"}),W=d.bins[0].bin_id,L=d.bins[d.bins.length-1].bin_id;if(t===void 0){L-W+1>1e3&&V("InvalidBinWidth",new Error("Width is too large"),{[Vt.METHOD_NAME]:"openPosition"});let tt=f.moveCall({target:`${S.published_at}::add_liquidity::open_position`,arguments:[typeof r=="string"?f.object(r):r,c,p,x,k,O,f.object(C),f.object(T),f.object(me)],typeArguments:[e,s]});l>=W&&l<=L&&this.validateActiveIdSlippage({pool_id:r,active_id:l,max_price_slippage:_,bin_step:y,coin_type_a:e,coin_type_b:s},f),f.transferObjects([c,p,tt],this.sdk.getSenderAddress())}else f.moveCall({target:`${S.published_at}::add_liquidity::add_liquidity`,arguments:[typeof r=="string"?f.object(r):r,f.object(t),c,p,x,k,O,f.object(C),f.object(T),f.object(me)],typeArguments:[e,s]}),l>=W&&l<=L&&this.validateActiveIdSlippage({pool_id:r,active_id:l,max_price_slippage:_,bin_step:y,coin_type_a:e,coin_type_b:s},f),f.transferObjects([c,p],this.sdk.getSenderAddress());return f}async fetchPositionFeeAndReward(i){let t=new be;this.collectRewardAndFeePayload(i,t);let r=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:t,sender:po("0x0")});if(r.error!=null)return V("FetchError",new Error(r.error),{[Vt.METHOD_NAME]:"fetchPositionFeeAndReward",[Vt.REQUEST_PARAMS]:{options:i,totalOptions:i.length}});let e=Or(r),s=xr(r);return{feeData:e,rewardData:s}}};import{Transaction as Zr}from"@mysten/sui/transactions";import{CLOCK_ADDRESS as qi,CoinAssist as mo,d as Ur,DETAILS_KEYS as Ve,getPackagerConfigs as Hr}from"@cetusprotocol/common-sdk";import{normalizeSuiAddress as _o}from"@mysten/sui/utils";var Xe=class{constructor(i){this._sdk=i}get sdk(){return this._sdk}async preSwapQuote(i){let{dlmm_pool:t}=this._sdk.sdkOptions,{pool_id:r,coin_type_a:e,coin_type_b:s,a2b:l,by_amount_in:d,in_amount:f}=i,{versioned_id:c,global_config_id:p}=Hr(t),_=new Zr;_.moveCall({target:`${t.published_at}::pool::flash_swap`,arguments:[_.object(r),_.pure.bool(l),_.pure.bool(d),_.pure.u64(f),_.object(p),_.object(c),_.object(qi)],typeArguments:[e,s]});let y=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:_,sender:_o("0x0")});if(y.error!=null)return V("FetchError",new Error(y.error),{[Ve.METHOD_NAME]:"fetchSwapQuote",[Ve.REQUEST_PARAMS]:i});let P=Tr(y,l);return P==null?V("FetchError",new Error("No quote info"),{[Ve.METHOD_NAME]:"preSwapQuote",[Ve.REQUEST_PARAMS]:i}):(P.a2b=l,P)}swapPayload(i){let{dlmm_pool:t,dlmm_router:r}=this._sdk.sdkOptions,{quote_obj:e,coin_type_a:s,coin_type_b:l,by_amount_in:d,slippage:f,partner:c}=i,{pool_id:p,in_amount:_,out_amount:y,a2b:P}=e,B=new Zr,S=d?_:Ur(_).mul(1+f).toFixed(0),T=d?Ur(y).mul(1-f).toFixed(0):y,C=mo.buildCoinWithBalance(BigInt(S),P?s:l,B),{versioned_id:k,global_config_id:O}=Hr(t);return console.log("\u{1F680} ~ SwapModule ~ option:",{...i,in_amount_limit:S,out_amount_limit:T}),c?B.moveCall({target:`${r.published_at}::swap::${P?"swap_a2b_with_partner":"swap_b2a_with_partner"}`,arguments:[B.object(p),B.object(c),C,B.pure.bool(d),B.pure.u64(BigInt(d?_:y)),B.pure.u64(BigInt(d?T:S)),B.object(O),B.object(k),B.object(qi)],typeArguments:[s,l]}):B.moveCall({target:`${r.published_at}::swap::${P?"swap_a2b":"swap_b2a"}`,arguments:[B.object(p),C,B.pure.bool(d),B.pure.u64(BigInt(d?_:y)),B.pure.u64(BigInt(d?T:S)),B.object(O),B.object(k),B.object(qi)],typeArguments:[s,l]}),B.transferObjects([C],this.sdk.getSenderAddress()),B}};import{Transaction as Je}from"@mysten/sui/transactions";import{CLOCK_ADDRESS as go,d as Qr,DETAILS_KEYS as Ht,fixCoinType as bo,getObjectFields as Li,getPackagerConfigs as Ce}from"@cetusprotocol/common-sdk";var Ye=class{constructor(i){this._sdk=i}get sdk(){return this._sdk}async getPartnerList(){let i=[],{dlmm_pool:t}=this._sdk.sdkOptions,{partners_id:r}=Ce(t);try{let e=await this._sdk.FullClient.getObject({id:r,options:{showContent:!0}}),l=Li(e).partners.fields.contents.map(d=>d.fields.value);l.length>0&&(await this._sdk.FullClient.batchGetObjects(l,{showContent:!0,showType:!0})).forEach(f=>{let c=Ri(f);i.push(c)})}catch(e){return V("FetchError",e,{[Ht.METHOD_NAME]:"getPartnerList",[Ht.REQUEST_PARAMS]:r})}return i}async getPartnerCapId(i,t){let{dlmm_pool:r}=this._sdk.sdkOptions;try{let e=`partner_cap_id_${i}_${t}`,s=this._sdk.getCache(e);if(s)return s;let l=await this._sdk.FullClient.getOwnedObjects({owner:i,options:{showContent:!0,showType:!0},filter:{StructType:`${r.package_id}::partner::PartnerCap`}}),d;return l.data.forEach(f=>{let c=Li(f);c.partner_id===t&&(d=c.id.id,this._sdk.updateCache(e,d))}),d||V("NotFound",new Error("Partner cap not found"),{[Ht.METHOD_NAME]:"getPartnerCapId",[Ht.REQUEST_PARAMS]:{owner:i,partner_id:t}})}catch(e){return V("FetchError",e,{[Ht.METHOD_NAME]:"getPartnerCapId",[Ht.REQUEST_PARAMS]:{owner:i,partner_id:t}})}}async getPartnerBalance(i){try{let t=await this._sdk.FullClient.getDynamicFieldsByPage(i),r=[],e=t.data.map(s=>s.objectId);return e.length>0&&(await this._sdk.FullClient.batchGetObjects(e,{showContent:!0,showType:!0})).forEach(l=>{let d=Li(l);console.log(d),r.push({coin_type:bo(d.name,!1),balance:d.value})}),r}catch(t){return V("FetchError",t,{[Ht.METHOD_NAME]:"getPartnerBalance",[Ht.REQUEST_PARAMS]:i})}}async getPartner(i){try{let t=await this._sdk.FullClient.getObject({id:i,options:{showContent:!0}});return Ri(t)}catch(t){return V("FetchError",t,{[Ht.METHOD_NAME]:"getPartner",[Ht.REQUEST_PARAMS]:i})}}updateRefFeeRatePayload(i,t){let{dlmm_pool:r}=this._sdk.sdkOptions,{partner_id:e,ref_fee_rate:s}=i,{global_config_id:l,versioned_id:d}=Ce(r);t=t||new Je;let f=Qr(s).mul(1e4);return f.gt(1e4)?V("InvalidParams",new Error("ref_fee_rate is cannot be greater than 1"),{[Ht.METHOD_NAME]:"updateRefFeeRatePayload",[Ht.REQUEST_PARAMS]:i}):(t.moveCall({target:`${r.published_at}::partner::update_ref_fee_rate`,arguments:[t.object(e),t.pure.u64(f.toNumber()),t.object(l),t.object(d)],typeArguments:[]}),t)}async claimRefFeePayload(i){let{partner_id:t,partner_cap_id:r,fee_coin_types:e}=i,{dlmm_pool:s}=this._sdk.sdkOptions,{versioned_id:l}=Ce(s),d=new Je,f=r;return f||(f=await this.getPartnerCapId(this._sdk.getSenderAddress(),t)),e.forEach(c=>{d.moveCall({target:`${s.published_at}::partner::claim_ref_fee`,arguments:[d.object(t),d.object(f),d.object(l)],typeArguments:[c]})}),d}updateTimeRangePayload(i,t){let{dlmm_pool:r}=this._sdk.sdkOptions,{partner_id:e,start_time:s,end_time:l}=i,{global_config_id:d,versioned_id:f}=Ce(r);t=t||new Je;let c=s>1e12?Math.floor(s/1e3):s,p=l>1e12?Math.floor(l/1e3):l;return p<=c?V("InvalidParams",new Error("end_time must be greater than start_time"),{[Ht.METHOD_NAME]:"createPartnerPayload",[Ht.REQUEST_PARAMS]:i}):(t.moveCall({target:`${r.published_at}::partner::update_time_range`,arguments:[t.object(e),t.pure.u64(c),t.pure.u64(p),t.object(d),t.object(f),t.object(go)],typeArguments:[]}),t)}createPartnerPayload(i){let{dlmm_pool:t}=this._sdk.sdkOptions,{name:r,ref_fee_rate:e,start_time:s,end_time:l,recipient:d}=i,{partners_id:f,global_config_id:c,versioned_id:p}=Ce(t),_=new Je,y=Qr(e).mul(1e4);if(y.gt(1e4))return V("InvalidParams",new Error("ref_fee_rate is cannot be greater than 1"),{[Ht.METHOD_NAME]:"createPartnerPayload",[Ht.REQUEST_PARAMS]:i});let P=s>1e12?Math.floor(s/1e3):s,B=l>1e12?Math.floor(l/1e3):l;return B<=P?V("InvalidParams",new Error("end_time must be greater than start_time"),{[Ht.METHOD_NAME]:"createPartnerPayload",[Ht.REQUEST_PARAMS]:i}):(_.moveCall({target:`${t.published_at}::partner::create_partner`,arguments:[_.object(f),_.pure.string(r),_.pure.u64(y.toNumber()),_.pure.u64(P),_.pure.u64(B),_.pure.address(d),_.object(c),_.object(p)],typeArguments:[]}),_)}};var Zi=Mi(ke());import{Transaction as ji}from"@mysten/sui/transactions";import{CLOCK_ADDRESS as Kr,CoinAssist as wo,d as Be,getObjectFields as vo,getPackagerConfigs as Wi,MathUtil as $r}from"@cetusprotocol/common-sdk";var ti=class{constructor(i){this._sdk=i}get sdk(){return this._sdk}async getRewardPeriodEmission(i,t,r){let e=await this._sdk.FullClient.getDynamicFieldsByPage(i),s=[],l=e.data.map(p=>p.objectId);l.length>0&&(await this._sdk.FullClient.batchGetObjects(l,{showContent:!0})).forEach(_=>{let y=vo(_),P=$r.u128ToI128(new Zi.default(y.value.fields.value.fields.bits)).toString(),B=y.name,S=new Date(Number(B)*1e3).toLocaleString(),C={emissions_per_second:"0",emissions_per_day:"0",emissions_per:$r.fromX64(new Zi.default(P)).toString(),time:B,visualized_time:S};s.push(C)});let d=s.sort((p,_)=>Number(p.time)-Number(_.time)),f=[];f.push({emissions_per_second:t,emissions_per_day:Be(t).mul(3600*24).toString(),emissions_per:"0",time:r.toString(),visualized_time:new Date(r*1e3).toLocaleString()});let c=t;for(let p=0;p<d.length;p++){let _=d[p];if(Be(_.time).lte(r))continue;c=Be(c).add(Be(_.emissions_per)).toString();let y=Be(c).mul(3600*24).toString();Be(c).lt(0)?(_.emissions_per_second="0",_.emissions_per_day="0"):(_.emissions_per_second=c,_.emissions_per_day=y),f.push(_)}return f}addRewardPayload(i,t){t=t||new ji;let{dlmm_pool:r}=this._sdk.sdkOptions,{global_config_id:e,versioned_id:s}=Wi(r),{pool_id:l,reward_coin_type:d,reward_amount:f,start_time_seconds:c,end_time_seconds:p,coin_type_a:_,coin_type_b:y}=i,P=wo.buildCoinWithBalance(BigInt(f),d,t);return t.pure.option("u64",c),t.moveCall({target:`${r.published_at}::pool::add_reward`,arguments:[t.object(l),P,t.pure.option("u64",c),t.pure.u64(p),t.object(e),t.object(s),t.object(Kr)],typeArguments:[_,y,d]}),t}initRewardPayload(i,t){t=t||new ji;let{dlmm_pool:r}=this._sdk.sdkOptions,{global_config_id:e,versioned_id:s}=Wi(r),{pool_id:l,reward_coin_types:d,coin_type_a:f,coin_type_b:c}=i;return d.forEach(p=>{t.moveCall({target:`${r.published_at}::pool::initialize_reward`,arguments:[t.object(l),t.object(e),t.object(s),t.object(Kr)],typeArguments:[f,c,p]})}),t}buildRewardAccessPayload(i,t){t=t||new ji;let{dlmm_pool:r}=this._sdk.sdkOptions,{global_config_id:e,versioned_id:s}=Wi(r),{pool_id:l,type:d,coin_type_a:f,coin_type_b:c}=i;return t.moveCall({target:`${r.published_at}::pool::${d==="to_public"?"make_reward_public":"make_reward_private"}`,arguments:[t.object(l),t.object(e),t.object(s)],typeArguments:[f,c]}),t}};import{Transaction as yo}from"@mysten/sui/transactions";import{DETAILS_KEYS as zr,fixCoinType as Mo,getObjectFields as Ui,getPackagerConfigs as Gr}from"@cetusprotocol/common-sdk";var ei=class{constructor(i){this._sdk=i}get sdk(){return this._sdk}buildRewardWhiteListPayload(i,t){t=t||new yo;let{dlmm_pool:r}=this._sdk.sdkOptions,{global_config_id:e,versioned_id:s}=Gr(r),{reward_coin_types:l,type:d}=i;return l.forEach(f=>{t.moveCall({target:`${r.published_at}::config::${d==="add"?"add_reward_whitelist":"remove_reward_whitelist"}`,arguments:[t.object(e),t.object(s)],typeArguments:[f]})}),t}async getBinStepConfigList(i){let t=await this._sdk.FullClient.getDynamicFieldsByPage(i),r=[],e=t.data.map(s=>s.objectId);return e.length>0&&(await this._sdk.FullClient.batchGetObjects(e,{showContent:!0})).forEach(l=>{let f={...Ui(l).value.fields};r.push(f)}),r}async getDlmmGlobalConfig(){let{dlmm_pool:i}=this._sdk.sdkOptions,{global_config_id:t}=Gr(i);try{let r=await this._sdk.FullClient.getObject({id:t,options:{showContent:!0}}),e=Ui(r),s=e.reward_config.fields,l=s.reward_white_list?.fields?.contents?.map(f=>Mo(f.fields.key.fields.name,!1))||[];return{id:e.id.id,acl:{id:e.acl.fields.permissions.fields.id.id,size:e.acl.fields.permissions.fields.size},allowed_list:{id:e.allowed_list.fields.id.id,size:e.allowed_list.fields.size},denied_list:{id:e.denied_list.fields.id.id,size:e.denied_list.fields.size},bin_steps:{id:e.bin_steps.fields.id.id,size:e.bin_steps.fields.size},reward_white_list:l,blocked_position:{id:e.restriction.fields.blocked_position.fields.permissions.fields.id.id,size:e.restriction.fields.blocked_position.fields.permissions.fields.size},blocked_user:{id:e.restriction.fields.blocked_user.fields.permissions.fields.id.id,size:e.restriction.fields.blocked_user.fields.permissions.fields.size},min_reward_duration:Number(s.min_reward_duration),non_manager_initialize_reward_cap:Number(s.manager_reserved_reward_init_slots),reward_public:s.reward_public}}catch(r){return console.log("fetchGlobalConfig error: ",r),V("FetchError",r,{[zr.METHOD_NAME]:"getBinStepConfigs",[zr.REQUEST_PARAMS]:t})}}async fetchDlmmSdkConfigs(){let{dlmm_pool:i}=this._sdk.sdkOptions,t={registry_id:"",pools_id:"",global_config_id:"",versioned_id:"",admin_cap_id:"",partners_id:""},e=(await this._sdk.FullClient.getObject({id:i.package_id,options:{showContent:!0,showPreviousTransaction:!0}})).data?.previousTransaction;(await this._sdk.FullClient.getTransactionBlock({digest:e,options:{showEvents:!0}})).events?.forEach(f=>{let c=f.type,p=f.parsedJson;c.includes("versioned::InitEvent")&&(t.versioned_id=p.versioned),c.includes("partner::InitPartnerEvent")&&(t.partners_id=p.partners_id),c.includes("config::InitEvent")&&(t.global_config_id=p.config_id),c.includes("admin_cap::InitEvent")&&(t.admin_cap_id=p.admin_cap_id),c.includes("registry::RegistryEvent")&&(t.registry_id=p.pools_id)});let l=await this._sdk.FullClient.getObject({id:t.registry_id,options:{showContent:!0}}),d=Ui(l);return t.pools_id=d.pools.fields.id.id,t}};var ii=class n extends Po{constructor(i){super(i),this._pool=new ze(this),this._position=new Ge(this),this._swap=new Xe(this),this._partner=new Ye(this),this._reward=new ti(this),this._config=new ei(this)}get Pool(){return this._pool}get Position(){return this._position}get Swap(){return this._swap}get Partner(){return this._partner}get Reward(){return this._reward}get Config(){return this._config}static createSDK(i){let{env:t="mainnet"}=i;return t==="mainnet"?n.createCustomSDK({...ar,...i}):n.createCustomSDK({...Wr,...i})}static createCustomSDK(i){return new n(i)}};var Al=ii;export{Jt as BASIS_POINT,he as BASIS_POINT_MAX,Me as BIN_BOUND,F as BinUtils,ii as CetusDlmmSDK,Oe as DEFAULT_MAX_WEIGHT,ye as DEFAULT_MIN_WEIGHT,Pr as FEE_PRECISION,Qe as FeeUtils,Dr as IlmUtils,Co as MAX_BIN_ID,ce as MAX_BIN_PER_POSITION,Oi as MAX_FEE_RATE,To as MIN_BIN_ID,xi as ONE,ze as PoolModule,ko as REWARD_PERIOD,Ro as REWARD_PERIOD_START_AT,q as SCALE_OFFSET,Ze as StrategyType,Te as StrategyUtils,Yt as WeightUtils,Rr as buildPoolKey,Al as default,ar as dlmmMainnet,Wr as dlmmTestnet,gs as generateRewardSchedule,kr as getRouterModule,Fi as parseBinInfo,Er as parseBinInfoList,ws as parseCurrentRewardPeriodEmission,Ir as parseDlmmBasePool,He as parseDlmmPool,Di as parseDlmmPosition,ms as parseLiquidityShares,Ri as parsePartner,Cr as parsePoolTransactionInfo,bs as parseRewardPeriodEmission,_s as parseStrategyType,Or as parsedDlmmPosFeeData,xr as parsedDlmmPosRewardData,Tr as parsedSwapQuoteData,oo as poolFilterEvenTypes,xe as safeAmount,oe as safeMulAmount};
1
+ var Vr=Object.create;var sr=Object.defineProperty;var Xr=Object.getOwnPropertyDescriptor;var Jr=Object.getOwnPropertyNames;var Yr=Object.getPrototypeOf,tn=Object.prototype.hasOwnProperty;var en=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(i,t)=>(typeof require<"u"?require:i)[t]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});var rn=(n,i)=>()=>(i||n((i={exports:{}}).exports,i),i.exports);var nn=(n,i,t,r)=>{if(i&&typeof i=="object"||typeof i=="function")for(let e of Jr(i))!tn.call(n,e)&&e!==t&&sr(n,e,{get:()=>i[e],enumerable:!(r=Xr(i,e))||r.enumerable});return n};var Mi=(n,i,t)=>(t=n!=null?Vr(Yr(n)):{},nn(i||!n||!n.__esModule?sr(t,"default",{value:n,enumerable:!0}):t,n));var xe=rn((lr,Pi)=>{"use strict";(function(n,i){"use strict";function t(v,o){if(!v)throw new Error(o||"Assertion failed")}function r(v,o){v.super_=o;var u=function(){};u.prototype=o.prototype,v.prototype=new u,v.prototype.constructor=v}function e(v,o,u){if(e.isBN(v))return v;this.negative=0,this.words=null,this.length=0,this.red=null,v!==null&&((o==="le"||o==="be")&&(u=o,o=10),this._init(v||0,o||10,u||"be"))}typeof n=="object"?n.exports=e:i.BN=e,e.BN=e,e.wordSize=26;var s;try{typeof window<"u"&&typeof window.Buffer<"u"?s=window.Buffer:s=en("buffer").Buffer}catch{}e.isBN=function(o){return o instanceof e?!0:o!==null&&typeof o=="object"&&o.constructor.wordSize===e.wordSize&&Array.isArray(o.words)},e.max=function(o,u){return o.cmp(u)>0?o:u},e.min=function(o,u){return o.cmp(u)<0?o:u},e.prototype._init=function(o,u,h){if(typeof o=="number")return this._initNumber(o,u,h);if(typeof o=="object")return this._initArray(o,u,h);u==="hex"&&(u=16),t(u===(u|0)&&u>=2&&u<=36),o=o.toString().replace(/\s+/g,"");var m=0;o[0]==="-"&&(m++,this.negative=1),m<o.length&&(u===16?this._parseHex(o,m,h):(this._parseBase(o,u,m),h==="le"&&this._initArray(this.toArray(),u,h)))},e.prototype._initNumber=function(o,u,h){o<0&&(this.negative=1,o=-o),o<67108864?(this.words=[o&67108863],this.length=1):o<4503599627370496?(this.words=[o&67108863,o/67108864&67108863],this.length=2):(t(o<9007199254740992),this.words=[o&67108863,o/67108864&67108863,1],this.length=3),h==="le"&&this._initArray(this.toArray(),u,h)},e.prototype._initArray=function(o,u,h){if(t(typeof o.length=="number"),o.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(o.length/3),this.words=new Array(this.length);for(var m=0;m<this.length;m++)this.words[m]=0;var b,M,P=0;if(h==="be")for(m=o.length-1,b=0;m>=0;m-=3)M=o[m]|o[m-1]<<8|o[m-2]<<16,this.words[b]|=M<<P&67108863,this.words[b+1]=M>>>26-P&67108863,P+=24,P>=26&&(P-=26,b++);else if(h==="le")for(m=0,b=0;m<o.length;m+=3)M=o[m]|o[m+1]<<8|o[m+2]<<16,this.words[b]|=M<<P&67108863,this.words[b+1]=M>>>26-P&67108863,P+=24,P>=26&&(P-=26,b++);return this._strip()};function l(v,o){var u=v.charCodeAt(o);if(u>=48&&u<=57)return u-48;if(u>=65&&u<=70)return u-55;if(u>=97&&u<=102)return u-87;t(!1,"Invalid character in "+v)}function d(v,o,u){var h=l(v,u);return u-1>=o&&(h|=l(v,u-1)<<4),h}e.prototype._parseHex=function(o,u,h){this.length=Math.ceil((o.length-u)/6),this.words=new Array(this.length);for(var m=0;m<this.length;m++)this.words[m]=0;var b=0,M=0,P;if(h==="be")for(m=o.length-1;m>=u;m-=2)P=d(o,u,m)<<b,this.words[M]|=P&67108863,b>=18?(b-=18,M+=1,this.words[M]|=P>>>26):b+=8;else{var g=o.length-u;for(m=g%2===0?u+1:u;m<o.length;m+=2)P=d(o,u,m)<<b,this.words[M]|=P&67108863,b>=18?(b-=18,M+=1,this.words[M]|=P>>>26):b+=8}this._strip()};function f(v,o,u,h){for(var m=0,b=0,M=Math.min(v.length,u),P=o;P<M;P++){var g=v.charCodeAt(P)-48;m*=h,g>=49?b=g-49+10:g>=17?b=g-17+10:b=g,t(g>=0&&b<h,"Invalid character"),m+=b}return m}e.prototype._parseBase=function(o,u,h){this.words=[0],this.length=1;for(var m=0,b=1;b<=67108863;b*=u)m++;m--,b=b/u|0;for(var M=o.length-h,P=M%m,g=Math.min(M,M-P)+h,a=0,w=h;w<g;w+=m)a=f(o,w,w+m,u),this.imuln(b),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a);if(P!==0){var R=1;for(a=f(o,w,o.length,u),w=0;w<P;w++)R*=u;this.imuln(R),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a)}this._strip()},e.prototype.copy=function(o){o.words=new Array(this.length);for(var u=0;u<this.length;u++)o.words[u]=this.words[u];o.length=this.length,o.negative=this.negative,o.red=this.red};function c(v,o){v.words=o.words,v.length=o.length,v.negative=o.negative,v.red=o.red}if(e.prototype._move=function(o){c(o,this)},e.prototype.clone=function(){var o=new e(null);return this.copy(o),o},e.prototype._expand=function(o){for(;this.length<o;)this.words[this.length++]=0;return this},e.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},e.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{e.prototype[Symbol.for("nodejs.util.inspect.custom")]=p}catch{e.prototype.inspect=p}else e.prototype.inspect=p;function p(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var _=["","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"],y=[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],A=[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];e.prototype.toString=function(o,u){o=o||10,u=u|0||1;var h;if(o===16||o==="hex"){h="";for(var m=0,b=0,M=0;M<this.length;M++){var P=this.words[M],g=((P<<m|b)&16777215).toString(16);b=P>>>24-m&16777215,m+=2,m>=26&&(m-=26,M--),b!==0||M!==this.length-1?h=_[6-g.length]+g+h:h=g+h}for(b!==0&&(h=b.toString(16)+h);h.length%u!==0;)h="0"+h;return this.negative!==0&&(h="-"+h),h}if(o===(o|0)&&o>=2&&o<=36){var a=y[o],w=A[o];h="";var R=this.clone();for(R.negative=0;!R.isZero();){var D=R.modrn(w).toString(o);R=R.idivn(w),R.isZero()?h=D+h:h=_[a-D.length]+D+h}for(this.isZero()&&(h="0"+h);h.length%u!==0;)h="0"+h;return this.negative!==0&&(h="-"+h),h}t(!1,"Base should be between 2 and 36")},e.prototype.toNumber=function(){var o=this.words[0];return this.length===2?o+=this.words[1]*67108864:this.length===3&&this.words[2]===1?o+=4503599627370496+this.words[1]*67108864:this.length>2&&t(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-o:o},e.prototype.toJSON=function(){return this.toString(16,2)},s&&(e.prototype.toBuffer=function(o,u){return this.toArrayLike(s,o,u)}),e.prototype.toArray=function(o,u){return this.toArrayLike(Array,o,u)};var B=function(o,u){return o.allocUnsafe?o.allocUnsafe(u):new o(u)};e.prototype.toArrayLike=function(o,u,h){this._strip();var m=this.byteLength(),b=h||Math.max(1,m);t(m<=b,"byte array longer than desired length"),t(b>0,"Requested array length <= 0");var M=B(o,b),P=u==="le"?"LE":"BE";return this["_toArrayLike"+P](M,m),M},e.prototype._toArrayLikeLE=function(o,u){for(var h=0,m=0,b=0,M=0;b<this.length;b++){var P=this.words[b]<<M|m;o[h++]=P&255,h<o.length&&(o[h++]=P>>8&255),h<o.length&&(o[h++]=P>>16&255),M===6?(h<o.length&&(o[h++]=P>>24&255),m=0,M=0):(m=P>>>24,M+=2)}if(h<o.length)for(o[h++]=m;h<o.length;)o[h++]=0},e.prototype._toArrayLikeBE=function(o,u){for(var h=o.length-1,m=0,b=0,M=0;b<this.length;b++){var P=this.words[b]<<M|m;o[h--]=P&255,h>=0&&(o[h--]=P>>8&255),h>=0&&(o[h--]=P>>16&255),M===6?(h>=0&&(o[h--]=P>>24&255),m=0,M=0):(m=P>>>24,M+=2)}if(h>=0)for(o[h--]=m;h>=0;)o[h--]=0},Math.clz32?e.prototype._countBits=function(o){return 32-Math.clz32(o)}:e.prototype._countBits=function(o){var u=o,h=0;return u>=4096&&(h+=13,u>>>=13),u>=64&&(h+=7,u>>>=7),u>=8&&(h+=4,u>>>=4),u>=2&&(h+=2,u>>>=2),h+u},e.prototype._zeroBits=function(o){if(o===0)return 26;var u=o,h=0;return(u&8191)===0&&(h+=13,u>>>=13),(u&127)===0&&(h+=7,u>>>=7),(u&15)===0&&(h+=4,u>>>=4),(u&3)===0&&(h+=2,u>>>=2),(u&1)===0&&h++,h},e.prototype.bitLength=function(){var o=this.words[this.length-1],u=this._countBits(o);return(this.length-1)*26+u};function S(v){for(var o=new Array(v.bitLength()),u=0;u<o.length;u++){var h=u/26|0,m=u%26;o[u]=v.words[h]>>>m&1}return o}e.prototype.zeroBits=function(){if(this.isZero())return 0;for(var o=0,u=0;u<this.length;u++){var h=this._zeroBits(this.words[u]);if(o+=h,h!==26)break}return o},e.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},e.prototype.toTwos=function(o){return this.negative!==0?this.abs().inotn(o).iaddn(1):this.clone()},e.prototype.fromTwos=function(o){return this.testn(o-1)?this.notn(o).iaddn(1).ineg():this.clone()},e.prototype.isNeg=function(){return this.negative!==0},e.prototype.neg=function(){return this.clone().ineg()},e.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},e.prototype.iuor=function(o){for(;this.length<o.length;)this.words[this.length++]=0;for(var u=0;u<o.length;u++)this.words[u]=this.words[u]|o.words[u];return this._strip()},e.prototype.ior=function(o){return t((this.negative|o.negative)===0),this.iuor(o)},e.prototype.or=function(o){return this.length>o.length?this.clone().ior(o):o.clone().ior(this)},e.prototype.uor=function(o){return this.length>o.length?this.clone().iuor(o):o.clone().iuor(this)},e.prototype.iuand=function(o){var u;this.length>o.length?u=o:u=this;for(var h=0;h<u.length;h++)this.words[h]=this.words[h]&o.words[h];return this.length=u.length,this._strip()},e.prototype.iand=function(o){return t((this.negative|o.negative)===0),this.iuand(o)},e.prototype.and=function(o){return this.length>o.length?this.clone().iand(o):o.clone().iand(this)},e.prototype.uand=function(o){return this.length>o.length?this.clone().iuand(o):o.clone().iuand(this)},e.prototype.iuxor=function(o){var u,h;this.length>o.length?(u=this,h=o):(u=o,h=this);for(var m=0;m<h.length;m++)this.words[m]=u.words[m]^h.words[m];if(this!==u)for(;m<u.length;m++)this.words[m]=u.words[m];return this.length=u.length,this._strip()},e.prototype.ixor=function(o){return t((this.negative|o.negative)===0),this.iuxor(o)},e.prototype.xor=function(o){return this.length>o.length?this.clone().ixor(o):o.clone().ixor(this)},e.prototype.uxor=function(o){return this.length>o.length?this.clone().iuxor(o):o.clone().iuxor(this)},e.prototype.inotn=function(o){t(typeof o=="number"&&o>=0);var u=Math.ceil(o/26)|0,h=o%26;this._expand(u),h>0&&u--;for(var m=0;m<u;m++)this.words[m]=~this.words[m]&67108863;return h>0&&(this.words[m]=~this.words[m]&67108863>>26-h),this._strip()},e.prototype.notn=function(o){return this.clone().inotn(o)},e.prototype.setn=function(o,u){t(typeof o=="number"&&o>=0);var h=o/26|0,m=o%26;return this._expand(h+1),u?this.words[h]=this.words[h]|1<<m:this.words[h]=this.words[h]&~(1<<m),this._strip()},e.prototype.iadd=function(o){var u;if(this.negative!==0&&o.negative===0)return this.negative=0,u=this.isub(o),this.negative^=1,this._normSign();if(this.negative===0&&o.negative!==0)return o.negative=0,u=this.isub(o),o.negative=1,u._normSign();var h,m;this.length>o.length?(h=this,m=o):(h=o,m=this);for(var b=0,M=0;M<m.length;M++)u=(h.words[M]|0)+(m.words[M]|0)+b,this.words[M]=u&67108863,b=u>>>26;for(;b!==0&&M<h.length;M++)u=(h.words[M]|0)+b,this.words[M]=u&67108863,b=u>>>26;if(this.length=h.length,b!==0)this.words[this.length]=b,this.length++;else if(h!==this)for(;M<h.length;M++)this.words[M]=h.words[M];return this},e.prototype.add=function(o){var u;return o.negative!==0&&this.negative===0?(o.negative=0,u=this.sub(o),o.negative^=1,u):o.negative===0&&this.negative!==0?(this.negative=0,u=o.sub(this),this.negative=1,u):this.length>o.length?this.clone().iadd(o):o.clone().iadd(this)},e.prototype.isub=function(o){if(o.negative!==0){o.negative=0;var u=this.iadd(o);return o.negative=1,u._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(o),this.negative=1,this._normSign();var h=this.cmp(o);if(h===0)return this.negative=0,this.length=1,this.words[0]=0,this;var m,b;h>0?(m=this,b=o):(m=o,b=this);for(var M=0,P=0;P<b.length;P++)u=(m.words[P]|0)-(b.words[P]|0)+M,M=u>>26,this.words[P]=u&67108863;for(;M!==0&&P<m.length;P++)u=(m.words[P]|0)+M,M=u>>26,this.words[P]=u&67108863;if(M===0&&P<m.length&&m!==this)for(;P<m.length;P++)this.words[P]=m.words[P];return this.length=Math.max(this.length,P),m!==this&&(this.negative=1),this._strip()},e.prototype.sub=function(o){return this.clone().isub(o)};function O(v,o,u){u.negative=o.negative^v.negative;var h=v.length+o.length|0;u.length=h,h=h-1|0;var m=v.words[0]|0,b=o.words[0]|0,M=m*b,P=M&67108863,g=M/67108864|0;u.words[0]=P;for(var a=1;a<h;a++){for(var w=g>>>26,R=g&67108863,D=Math.min(a,o.length-1),W=Math.max(0,a-v.length+1);W<=D;W++){var z=a-W|0;m=v.words[z]|0,b=o.words[W]|0,M=m*b+R,w+=M/67108864|0,R=M&67108863}u.words[a]=R|0,g=w|0}return g!==0?u.words[a]=g|0:u.length--,u._strip()}var k=function(o,u,h){var m=o.words,b=u.words,M=h.words,P=0,g,a,w,R=m[0]|0,D=R&8191,W=R>>>13,z=m[1]|0,J=z&8191,L=z>>>13,et=m[2]|0,H=et&8191,Y=et>>>13,Se=m[3]|0,ut=Se&8191,dt=Se>>>13,Hi=m[4]|0,ft=Hi&8191,ct=Hi>>>13,Qi=m[5]|0,ht=Qi&8191,pt=Qi>>>13,Ki=m[6]|0,mt=Ki&8191,_t=Ki>>>13,$i=m[7]|0,gt=$i&8191,bt=$i>>>13,zi=m[8]|0,wt=zi&8191,vt=zi>>>13,Gi=m[9]|0,yt=Gi&8191,Mt=Gi>>>13,Vi=b[0]|0,Pt=Vi&8191,At=Vi>>>13,Xi=b[1]|0,Bt=Xi&8191,St=Xi>>>13,Ji=b[2]|0,It=Ji&8191,Et=Ji>>>13,Yi=b[3]|0,Ot=Yi&8191,Tt=Yi>>>13,tr=b[4]|0,Ct=tr&8191,kt=tr>>>13,er=b[5]|0,xt=er&8191,Rt=er>>>13,ir=b[6]|0,Dt=ir&8191,Ft=ir>>>13,rr=b[7]|0,Nt=rr&8191,Lt=rr>>>13,nr=b[8]|0,qt=nr&8191,jt=nr>>>13,or=b[9]|0,Wt=or&8191,Zt=or>>>13;h.negative=o.negative^u.negative,h.length=19,g=Math.imul(D,Pt),a=Math.imul(D,At),a=a+Math.imul(W,Pt)|0,w=Math.imul(W,At);var ri=(P+g|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(ri>>>26)|0,ri&=67108863,g=Math.imul(J,Pt),a=Math.imul(J,At),a=a+Math.imul(L,Pt)|0,w=Math.imul(L,At),g=g+Math.imul(D,Bt)|0,a=a+Math.imul(D,St)|0,a=a+Math.imul(W,Bt)|0,w=w+Math.imul(W,St)|0;var ni=(P+g|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(ni>>>26)|0,ni&=67108863,g=Math.imul(H,Pt),a=Math.imul(H,At),a=a+Math.imul(Y,Pt)|0,w=Math.imul(Y,At),g=g+Math.imul(J,Bt)|0,a=a+Math.imul(J,St)|0,a=a+Math.imul(L,Bt)|0,w=w+Math.imul(L,St)|0,g=g+Math.imul(D,It)|0,a=a+Math.imul(D,Et)|0,a=a+Math.imul(W,It)|0,w=w+Math.imul(W,Et)|0;var oi=(P+g|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(oi>>>26)|0,oi&=67108863,g=Math.imul(ut,Pt),a=Math.imul(ut,At),a=a+Math.imul(dt,Pt)|0,w=Math.imul(dt,At),g=g+Math.imul(H,Bt)|0,a=a+Math.imul(H,St)|0,a=a+Math.imul(Y,Bt)|0,w=w+Math.imul(Y,St)|0,g=g+Math.imul(J,It)|0,a=a+Math.imul(J,Et)|0,a=a+Math.imul(L,It)|0,w=w+Math.imul(L,Et)|0,g=g+Math.imul(D,Ot)|0,a=a+Math.imul(D,Tt)|0,a=a+Math.imul(W,Ot)|0,w=w+Math.imul(W,Tt)|0;var si=(P+g|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(si>>>26)|0,si&=67108863,g=Math.imul(ft,Pt),a=Math.imul(ft,At),a=a+Math.imul(ct,Pt)|0,w=Math.imul(ct,At),g=g+Math.imul(ut,Bt)|0,a=a+Math.imul(ut,St)|0,a=a+Math.imul(dt,Bt)|0,w=w+Math.imul(dt,St)|0,g=g+Math.imul(H,It)|0,a=a+Math.imul(H,Et)|0,a=a+Math.imul(Y,It)|0,w=w+Math.imul(Y,Et)|0,g=g+Math.imul(J,Ot)|0,a=a+Math.imul(J,Tt)|0,a=a+Math.imul(L,Ot)|0,w=w+Math.imul(L,Tt)|0,g=g+Math.imul(D,Ct)|0,a=a+Math.imul(D,kt)|0,a=a+Math.imul(W,Ct)|0,w=w+Math.imul(W,kt)|0;var ai=(P+g|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(ai>>>26)|0,ai&=67108863,g=Math.imul(ht,Pt),a=Math.imul(ht,At),a=a+Math.imul(pt,Pt)|0,w=Math.imul(pt,At),g=g+Math.imul(ft,Bt)|0,a=a+Math.imul(ft,St)|0,a=a+Math.imul(ct,Bt)|0,w=w+Math.imul(ct,St)|0,g=g+Math.imul(ut,It)|0,a=a+Math.imul(ut,Et)|0,a=a+Math.imul(dt,It)|0,w=w+Math.imul(dt,Et)|0,g=g+Math.imul(H,Ot)|0,a=a+Math.imul(H,Tt)|0,a=a+Math.imul(Y,Ot)|0,w=w+Math.imul(Y,Tt)|0,g=g+Math.imul(J,Ct)|0,a=a+Math.imul(J,kt)|0,a=a+Math.imul(L,Ct)|0,w=w+Math.imul(L,kt)|0,g=g+Math.imul(D,xt)|0,a=a+Math.imul(D,Rt)|0,a=a+Math.imul(W,xt)|0,w=w+Math.imul(W,Rt)|0;var li=(P+g|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(li>>>26)|0,li&=67108863,g=Math.imul(mt,Pt),a=Math.imul(mt,At),a=a+Math.imul(_t,Pt)|0,w=Math.imul(_t,At),g=g+Math.imul(ht,Bt)|0,a=a+Math.imul(ht,St)|0,a=a+Math.imul(pt,Bt)|0,w=w+Math.imul(pt,St)|0,g=g+Math.imul(ft,It)|0,a=a+Math.imul(ft,Et)|0,a=a+Math.imul(ct,It)|0,w=w+Math.imul(ct,Et)|0,g=g+Math.imul(ut,Ot)|0,a=a+Math.imul(ut,Tt)|0,a=a+Math.imul(dt,Ot)|0,w=w+Math.imul(dt,Tt)|0,g=g+Math.imul(H,Ct)|0,a=a+Math.imul(H,kt)|0,a=a+Math.imul(Y,Ct)|0,w=w+Math.imul(Y,kt)|0,g=g+Math.imul(J,xt)|0,a=a+Math.imul(J,Rt)|0,a=a+Math.imul(L,xt)|0,w=w+Math.imul(L,Rt)|0,g=g+Math.imul(D,Dt)|0,a=a+Math.imul(D,Ft)|0,a=a+Math.imul(W,Dt)|0,w=w+Math.imul(W,Ft)|0;var ui=(P+g|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(ui>>>26)|0,ui&=67108863,g=Math.imul(gt,Pt),a=Math.imul(gt,At),a=a+Math.imul(bt,Pt)|0,w=Math.imul(bt,At),g=g+Math.imul(mt,Bt)|0,a=a+Math.imul(mt,St)|0,a=a+Math.imul(_t,Bt)|0,w=w+Math.imul(_t,St)|0,g=g+Math.imul(ht,It)|0,a=a+Math.imul(ht,Et)|0,a=a+Math.imul(pt,It)|0,w=w+Math.imul(pt,Et)|0,g=g+Math.imul(ft,Ot)|0,a=a+Math.imul(ft,Tt)|0,a=a+Math.imul(ct,Ot)|0,w=w+Math.imul(ct,Tt)|0,g=g+Math.imul(ut,Ct)|0,a=a+Math.imul(ut,kt)|0,a=a+Math.imul(dt,Ct)|0,w=w+Math.imul(dt,kt)|0,g=g+Math.imul(H,xt)|0,a=a+Math.imul(H,Rt)|0,a=a+Math.imul(Y,xt)|0,w=w+Math.imul(Y,Rt)|0,g=g+Math.imul(J,Dt)|0,a=a+Math.imul(J,Ft)|0,a=a+Math.imul(L,Dt)|0,w=w+Math.imul(L,Ft)|0,g=g+Math.imul(D,Nt)|0,a=a+Math.imul(D,Lt)|0,a=a+Math.imul(W,Nt)|0,w=w+Math.imul(W,Lt)|0;var di=(P+g|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(di>>>26)|0,di&=67108863,g=Math.imul(wt,Pt),a=Math.imul(wt,At),a=a+Math.imul(vt,Pt)|0,w=Math.imul(vt,At),g=g+Math.imul(gt,Bt)|0,a=a+Math.imul(gt,St)|0,a=a+Math.imul(bt,Bt)|0,w=w+Math.imul(bt,St)|0,g=g+Math.imul(mt,It)|0,a=a+Math.imul(mt,Et)|0,a=a+Math.imul(_t,It)|0,w=w+Math.imul(_t,Et)|0,g=g+Math.imul(ht,Ot)|0,a=a+Math.imul(ht,Tt)|0,a=a+Math.imul(pt,Ot)|0,w=w+Math.imul(pt,Tt)|0,g=g+Math.imul(ft,Ct)|0,a=a+Math.imul(ft,kt)|0,a=a+Math.imul(ct,Ct)|0,w=w+Math.imul(ct,kt)|0,g=g+Math.imul(ut,xt)|0,a=a+Math.imul(ut,Rt)|0,a=a+Math.imul(dt,xt)|0,w=w+Math.imul(dt,Rt)|0,g=g+Math.imul(H,Dt)|0,a=a+Math.imul(H,Ft)|0,a=a+Math.imul(Y,Dt)|0,w=w+Math.imul(Y,Ft)|0,g=g+Math.imul(J,Nt)|0,a=a+Math.imul(J,Lt)|0,a=a+Math.imul(L,Nt)|0,w=w+Math.imul(L,Lt)|0,g=g+Math.imul(D,qt)|0,a=a+Math.imul(D,jt)|0,a=a+Math.imul(W,qt)|0,w=w+Math.imul(W,jt)|0;var fi=(P+g|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(fi>>>26)|0,fi&=67108863,g=Math.imul(yt,Pt),a=Math.imul(yt,At),a=a+Math.imul(Mt,Pt)|0,w=Math.imul(Mt,At),g=g+Math.imul(wt,Bt)|0,a=a+Math.imul(wt,St)|0,a=a+Math.imul(vt,Bt)|0,w=w+Math.imul(vt,St)|0,g=g+Math.imul(gt,It)|0,a=a+Math.imul(gt,Et)|0,a=a+Math.imul(bt,It)|0,w=w+Math.imul(bt,Et)|0,g=g+Math.imul(mt,Ot)|0,a=a+Math.imul(mt,Tt)|0,a=a+Math.imul(_t,Ot)|0,w=w+Math.imul(_t,Tt)|0,g=g+Math.imul(ht,Ct)|0,a=a+Math.imul(ht,kt)|0,a=a+Math.imul(pt,Ct)|0,w=w+Math.imul(pt,kt)|0,g=g+Math.imul(ft,xt)|0,a=a+Math.imul(ft,Rt)|0,a=a+Math.imul(ct,xt)|0,w=w+Math.imul(ct,Rt)|0,g=g+Math.imul(ut,Dt)|0,a=a+Math.imul(ut,Ft)|0,a=a+Math.imul(dt,Dt)|0,w=w+Math.imul(dt,Ft)|0,g=g+Math.imul(H,Nt)|0,a=a+Math.imul(H,Lt)|0,a=a+Math.imul(Y,Nt)|0,w=w+Math.imul(Y,Lt)|0,g=g+Math.imul(J,qt)|0,a=a+Math.imul(J,jt)|0,a=a+Math.imul(L,qt)|0,w=w+Math.imul(L,jt)|0,g=g+Math.imul(D,Wt)|0,a=a+Math.imul(D,Zt)|0,a=a+Math.imul(W,Wt)|0,w=w+Math.imul(W,Zt)|0;var ci=(P+g|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(ci>>>26)|0,ci&=67108863,g=Math.imul(yt,Bt),a=Math.imul(yt,St),a=a+Math.imul(Mt,Bt)|0,w=Math.imul(Mt,St),g=g+Math.imul(wt,It)|0,a=a+Math.imul(wt,Et)|0,a=a+Math.imul(vt,It)|0,w=w+Math.imul(vt,Et)|0,g=g+Math.imul(gt,Ot)|0,a=a+Math.imul(gt,Tt)|0,a=a+Math.imul(bt,Ot)|0,w=w+Math.imul(bt,Tt)|0,g=g+Math.imul(mt,Ct)|0,a=a+Math.imul(mt,kt)|0,a=a+Math.imul(_t,Ct)|0,w=w+Math.imul(_t,kt)|0,g=g+Math.imul(ht,xt)|0,a=a+Math.imul(ht,Rt)|0,a=a+Math.imul(pt,xt)|0,w=w+Math.imul(pt,Rt)|0,g=g+Math.imul(ft,Dt)|0,a=a+Math.imul(ft,Ft)|0,a=a+Math.imul(ct,Dt)|0,w=w+Math.imul(ct,Ft)|0,g=g+Math.imul(ut,Nt)|0,a=a+Math.imul(ut,Lt)|0,a=a+Math.imul(dt,Nt)|0,w=w+Math.imul(dt,Lt)|0,g=g+Math.imul(H,qt)|0,a=a+Math.imul(H,jt)|0,a=a+Math.imul(Y,qt)|0,w=w+Math.imul(Y,jt)|0,g=g+Math.imul(J,Wt)|0,a=a+Math.imul(J,Zt)|0,a=a+Math.imul(L,Wt)|0,w=w+Math.imul(L,Zt)|0;var hi=(P+g|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(hi>>>26)|0,hi&=67108863,g=Math.imul(yt,It),a=Math.imul(yt,Et),a=a+Math.imul(Mt,It)|0,w=Math.imul(Mt,Et),g=g+Math.imul(wt,Ot)|0,a=a+Math.imul(wt,Tt)|0,a=a+Math.imul(vt,Ot)|0,w=w+Math.imul(vt,Tt)|0,g=g+Math.imul(gt,Ct)|0,a=a+Math.imul(gt,kt)|0,a=a+Math.imul(bt,Ct)|0,w=w+Math.imul(bt,kt)|0,g=g+Math.imul(mt,xt)|0,a=a+Math.imul(mt,Rt)|0,a=a+Math.imul(_t,xt)|0,w=w+Math.imul(_t,Rt)|0,g=g+Math.imul(ht,Dt)|0,a=a+Math.imul(ht,Ft)|0,a=a+Math.imul(pt,Dt)|0,w=w+Math.imul(pt,Ft)|0,g=g+Math.imul(ft,Nt)|0,a=a+Math.imul(ft,Lt)|0,a=a+Math.imul(ct,Nt)|0,w=w+Math.imul(ct,Lt)|0,g=g+Math.imul(ut,qt)|0,a=a+Math.imul(ut,jt)|0,a=a+Math.imul(dt,qt)|0,w=w+Math.imul(dt,jt)|0,g=g+Math.imul(H,Wt)|0,a=a+Math.imul(H,Zt)|0,a=a+Math.imul(Y,Wt)|0,w=w+Math.imul(Y,Zt)|0;var pi=(P+g|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(pi>>>26)|0,pi&=67108863,g=Math.imul(yt,Ot),a=Math.imul(yt,Tt),a=a+Math.imul(Mt,Ot)|0,w=Math.imul(Mt,Tt),g=g+Math.imul(wt,Ct)|0,a=a+Math.imul(wt,kt)|0,a=a+Math.imul(vt,Ct)|0,w=w+Math.imul(vt,kt)|0,g=g+Math.imul(gt,xt)|0,a=a+Math.imul(gt,Rt)|0,a=a+Math.imul(bt,xt)|0,w=w+Math.imul(bt,Rt)|0,g=g+Math.imul(mt,Dt)|0,a=a+Math.imul(mt,Ft)|0,a=a+Math.imul(_t,Dt)|0,w=w+Math.imul(_t,Ft)|0,g=g+Math.imul(ht,Nt)|0,a=a+Math.imul(ht,Lt)|0,a=a+Math.imul(pt,Nt)|0,w=w+Math.imul(pt,Lt)|0,g=g+Math.imul(ft,qt)|0,a=a+Math.imul(ft,jt)|0,a=a+Math.imul(ct,qt)|0,w=w+Math.imul(ct,jt)|0,g=g+Math.imul(ut,Wt)|0,a=a+Math.imul(ut,Zt)|0,a=a+Math.imul(dt,Wt)|0,w=w+Math.imul(dt,Zt)|0;var mi=(P+g|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(mi>>>26)|0,mi&=67108863,g=Math.imul(yt,Ct),a=Math.imul(yt,kt),a=a+Math.imul(Mt,Ct)|0,w=Math.imul(Mt,kt),g=g+Math.imul(wt,xt)|0,a=a+Math.imul(wt,Rt)|0,a=a+Math.imul(vt,xt)|0,w=w+Math.imul(vt,Rt)|0,g=g+Math.imul(gt,Dt)|0,a=a+Math.imul(gt,Ft)|0,a=a+Math.imul(bt,Dt)|0,w=w+Math.imul(bt,Ft)|0,g=g+Math.imul(mt,Nt)|0,a=a+Math.imul(mt,Lt)|0,a=a+Math.imul(_t,Nt)|0,w=w+Math.imul(_t,Lt)|0,g=g+Math.imul(ht,qt)|0,a=a+Math.imul(ht,jt)|0,a=a+Math.imul(pt,qt)|0,w=w+Math.imul(pt,jt)|0,g=g+Math.imul(ft,Wt)|0,a=a+Math.imul(ft,Zt)|0,a=a+Math.imul(ct,Wt)|0,w=w+Math.imul(ct,Zt)|0;var _i=(P+g|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(_i>>>26)|0,_i&=67108863,g=Math.imul(yt,xt),a=Math.imul(yt,Rt),a=a+Math.imul(Mt,xt)|0,w=Math.imul(Mt,Rt),g=g+Math.imul(wt,Dt)|0,a=a+Math.imul(wt,Ft)|0,a=a+Math.imul(vt,Dt)|0,w=w+Math.imul(vt,Ft)|0,g=g+Math.imul(gt,Nt)|0,a=a+Math.imul(gt,Lt)|0,a=a+Math.imul(bt,Nt)|0,w=w+Math.imul(bt,Lt)|0,g=g+Math.imul(mt,qt)|0,a=a+Math.imul(mt,jt)|0,a=a+Math.imul(_t,qt)|0,w=w+Math.imul(_t,jt)|0,g=g+Math.imul(ht,Wt)|0,a=a+Math.imul(ht,Zt)|0,a=a+Math.imul(pt,Wt)|0,w=w+Math.imul(pt,Zt)|0;var gi=(P+g|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(gi>>>26)|0,gi&=67108863,g=Math.imul(yt,Dt),a=Math.imul(yt,Ft),a=a+Math.imul(Mt,Dt)|0,w=Math.imul(Mt,Ft),g=g+Math.imul(wt,Nt)|0,a=a+Math.imul(wt,Lt)|0,a=a+Math.imul(vt,Nt)|0,w=w+Math.imul(vt,Lt)|0,g=g+Math.imul(gt,qt)|0,a=a+Math.imul(gt,jt)|0,a=a+Math.imul(bt,qt)|0,w=w+Math.imul(bt,jt)|0,g=g+Math.imul(mt,Wt)|0,a=a+Math.imul(mt,Zt)|0,a=a+Math.imul(_t,Wt)|0,w=w+Math.imul(_t,Zt)|0;var bi=(P+g|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(bi>>>26)|0,bi&=67108863,g=Math.imul(yt,Nt),a=Math.imul(yt,Lt),a=a+Math.imul(Mt,Nt)|0,w=Math.imul(Mt,Lt),g=g+Math.imul(wt,qt)|0,a=a+Math.imul(wt,jt)|0,a=a+Math.imul(vt,qt)|0,w=w+Math.imul(vt,jt)|0,g=g+Math.imul(gt,Wt)|0,a=a+Math.imul(gt,Zt)|0,a=a+Math.imul(bt,Wt)|0,w=w+Math.imul(bt,Zt)|0;var wi=(P+g|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(wi>>>26)|0,wi&=67108863,g=Math.imul(yt,qt),a=Math.imul(yt,jt),a=a+Math.imul(Mt,qt)|0,w=Math.imul(Mt,jt),g=g+Math.imul(wt,Wt)|0,a=a+Math.imul(wt,Zt)|0,a=a+Math.imul(vt,Wt)|0,w=w+Math.imul(vt,Zt)|0;var vi=(P+g|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(vi>>>26)|0,vi&=67108863,g=Math.imul(yt,Wt),a=Math.imul(yt,Zt),a=a+Math.imul(Mt,Wt)|0,w=Math.imul(Mt,Zt);var yi=(P+g|0)+((a&8191)<<13)|0;return P=(w+(a>>>13)|0)+(yi>>>26)|0,yi&=67108863,M[0]=ri,M[1]=ni,M[2]=oi,M[3]=si,M[4]=ai,M[5]=li,M[6]=ui,M[7]=di,M[8]=fi,M[9]=ci,M[10]=hi,M[11]=pi,M[12]=mi,M[13]=_i,M[14]=gi,M[15]=bi,M[16]=wi,M[17]=vi,M[18]=yi,P!==0&&(M[19]=P,h.length++),h};Math.imul||(k=O);function x(v,o,u){u.negative=o.negative^v.negative,u.length=v.length+o.length;for(var h=0,m=0,b=0;b<u.length-1;b++){var M=m;m=0;for(var P=h&67108863,g=Math.min(b,o.length-1),a=Math.max(0,b-v.length+1);a<=g;a++){var w=b-a,R=v.words[w]|0,D=o.words[a]|0,W=R*D,z=W&67108863;M=M+(W/67108864|0)|0,z=z+P|0,P=z&67108863,M=M+(z>>>26)|0,m+=M>>>26,M&=67108863}u.words[b]=P,h=M,M=m}return h!==0?u.words[b]=h:u.length--,u._strip()}function T(v,o,u){return x(v,o,u)}e.prototype.mulTo=function(o,u){var h,m=this.length+o.length;return this.length===10&&o.length===10?h=k(this,o,u):m<63?h=O(this,o,u):m<1024?h=x(this,o,u):h=T(this,o,u),h};function C(v,o){this.x=v,this.y=o}C.prototype.makeRBT=function(o){for(var u=new Array(o),h=e.prototype._countBits(o)-1,m=0;m<o;m++)u[m]=this.revBin(m,h,o);return u},C.prototype.revBin=function(o,u,h){if(o===0||o===h-1)return o;for(var m=0,b=0;b<u;b++)m|=(o&1)<<u-b-1,o>>=1;return m},C.prototype.permute=function(o,u,h,m,b,M){for(var P=0;P<M;P++)m[P]=u[o[P]],b[P]=h[o[P]]},C.prototype.transform=function(o,u,h,m,b,M){this.permute(M,o,u,h,m,b);for(var P=1;P<b;P<<=1)for(var g=P<<1,a=Math.cos(2*Math.PI/g),w=Math.sin(2*Math.PI/g),R=0;R<b;R+=g)for(var D=a,W=w,z=0;z<P;z++){var J=h[R+z],L=m[R+z],et=h[R+z+P],H=m[R+z+P],Y=D*et-W*H;H=D*H+W*et,et=Y,h[R+z]=J+et,m[R+z]=L+H,h[R+z+P]=J-et,m[R+z+P]=L-H,z!==g&&(Y=a*D-w*W,W=a*W+w*D,D=Y)}},C.prototype.guessLen13b=function(o,u){var h=Math.max(u,o)|1,m=h&1,b=0;for(h=h/2|0;h;h=h>>>1)b++;return 1<<b+1+m},C.prototype.conjugate=function(o,u,h){if(!(h<=1))for(var m=0;m<h/2;m++){var b=o[m];o[m]=o[h-m-1],o[h-m-1]=b,b=u[m],u[m]=-u[h-m-1],u[h-m-1]=-b}},C.prototype.normalize13b=function(o,u){for(var h=0,m=0;m<u/2;m++){var b=Math.round(o[2*m+1]/u)*8192+Math.round(o[2*m]/u)+h;o[m]=b&67108863,b<67108864?h=0:h=b/67108864|0}return o},C.prototype.convert13b=function(o,u,h,m){for(var b=0,M=0;M<u;M++)b=b+(o[M]|0),h[2*M]=b&8191,b=b>>>13,h[2*M+1]=b&8191,b=b>>>13;for(M=2*u;M<m;++M)h[M]=0;t(b===0),t((b&-8192)===0)},C.prototype.stub=function(o){for(var u=new Array(o),h=0;h<o;h++)u[h]=0;return u},C.prototype.mulp=function(o,u,h){var m=2*this.guessLen13b(o.length,u.length),b=this.makeRBT(m),M=this.stub(m),P=new Array(m),g=new Array(m),a=new Array(m),w=new Array(m),R=new Array(m),D=new Array(m),W=h.words;W.length=m,this.convert13b(o.words,o.length,P,m),this.convert13b(u.words,u.length,w,m),this.transform(P,M,g,a,m,b),this.transform(w,M,R,D,m,b);for(var z=0;z<m;z++){var J=g[z]*R[z]-a[z]*D[z];a[z]=g[z]*D[z]+a[z]*R[z],g[z]=J}return this.conjugate(g,a,m),this.transform(g,a,W,M,m,b),this.conjugate(W,M,m),this.normalize13b(W,m),h.negative=o.negative^u.negative,h.length=o.length+u.length,h._strip()},e.prototype.mul=function(o){var u=new e(null);return u.words=new Array(this.length+o.length),this.mulTo(o,u)},e.prototype.mulf=function(o){var u=new e(null);return u.words=new Array(this.length+o.length),T(this,o,u)},e.prototype.imul=function(o){return this.clone().mulTo(o,this)},e.prototype.imuln=function(o){var u=o<0;u&&(o=-o),t(typeof o=="number"),t(o<67108864);for(var h=0,m=0;m<this.length;m++){var b=(this.words[m]|0)*o,M=(b&67108863)+(h&67108863);h>>=26,h+=b/67108864|0,h+=M>>>26,this.words[m]=M&67108863}return h!==0&&(this.words[m]=h,this.length++),this.length=o===0?1:this.length,u?this.ineg():this},e.prototype.muln=function(o){return this.clone().imuln(o)},e.prototype.sqr=function(){return this.mul(this)},e.prototype.isqr=function(){return this.imul(this.clone())},e.prototype.pow=function(o){var u=S(o);if(u.length===0)return new e(1);for(var h=this,m=0;m<u.length&&u[m]===0;m++,h=h.sqr());if(++m<u.length)for(var b=h.sqr();m<u.length;m++,b=b.sqr())u[m]!==0&&(h=h.mul(b));return h},e.prototype.iushln=function(o){t(typeof o=="number"&&o>=0);var u=o%26,h=(o-u)/26,m=67108863>>>26-u<<26-u,b;if(u!==0){var M=0;for(b=0;b<this.length;b++){var P=this.words[b]&m,g=(this.words[b]|0)-P<<u;this.words[b]=g|M,M=P>>>26-u}M&&(this.words[b]=M,this.length++)}if(h!==0){for(b=this.length-1;b>=0;b--)this.words[b+h]=this.words[b];for(b=0;b<h;b++)this.words[b]=0;this.length+=h}return this._strip()},e.prototype.ishln=function(o){return t(this.negative===0),this.iushln(o)},e.prototype.iushrn=function(o,u,h){t(typeof o=="number"&&o>=0);var m;u?m=(u-u%26)/26:m=0;var b=o%26,M=Math.min((o-b)/26,this.length),P=67108863^67108863>>>b<<b,g=h;if(m-=M,m=Math.max(0,m),g){for(var a=0;a<M;a++)g.words[a]=this.words[a];g.length=M}if(M!==0)if(this.length>M)for(this.length-=M,a=0;a<this.length;a++)this.words[a]=this.words[a+M];else this.words[0]=0,this.length=1;var w=0;for(a=this.length-1;a>=0&&(w!==0||a>=m);a--){var R=this.words[a]|0;this.words[a]=w<<26-b|R>>>b,w=R&P}return g&&w!==0&&(g.words[g.length++]=w),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},e.prototype.ishrn=function(o,u,h){return t(this.negative===0),this.iushrn(o,u,h)},e.prototype.shln=function(o){return this.clone().ishln(o)},e.prototype.ushln=function(o){return this.clone().iushln(o)},e.prototype.shrn=function(o){return this.clone().ishrn(o)},e.prototype.ushrn=function(o){return this.clone().iushrn(o)},e.prototype.testn=function(o){t(typeof o=="number"&&o>=0);var u=o%26,h=(o-u)/26,m=1<<u;if(this.length<=h)return!1;var b=this.words[h];return!!(b&m)},e.prototype.imaskn=function(o){t(typeof o=="number"&&o>=0);var u=o%26,h=(o-u)/26;if(t(this.negative===0,"imaskn works only with positive numbers"),this.length<=h)return this;if(u!==0&&h++,this.length=Math.min(h,this.length),u!==0){var m=67108863^67108863>>>u<<u;this.words[this.length-1]&=m}return this._strip()},e.prototype.maskn=function(o){return this.clone().imaskn(o)},e.prototype.iaddn=function(o){return t(typeof o=="number"),t(o<67108864),o<0?this.isubn(-o):this.negative!==0?this.length===1&&(this.words[0]|0)<=o?(this.words[0]=o-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(o),this.negative=1,this):this._iaddn(o)},e.prototype._iaddn=function(o){this.words[0]+=o;for(var u=0;u<this.length&&this.words[u]>=67108864;u++)this.words[u]-=67108864,u===this.length-1?this.words[u+1]=1:this.words[u+1]++;return this.length=Math.max(this.length,u+1),this},e.prototype.isubn=function(o){if(t(typeof o=="number"),t(o<67108864),o<0)return this.iaddn(-o);if(this.negative!==0)return this.negative=0,this.iaddn(o),this.negative=1,this;if(this.words[0]-=o,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var u=0;u<this.length&&this.words[u]<0;u++)this.words[u]+=67108864,this.words[u+1]-=1;return this._strip()},e.prototype.addn=function(o){return this.clone().iaddn(o)},e.prototype.subn=function(o){return this.clone().isubn(o)},e.prototype.iabs=function(){return this.negative=0,this},e.prototype.abs=function(){return this.clone().iabs()},e.prototype._ishlnsubmul=function(o,u,h){var m=o.length+h,b;this._expand(m);var M,P=0;for(b=0;b<o.length;b++){M=(this.words[b+h]|0)+P;var g=(o.words[b]|0)*u;M-=g&67108863,P=(M>>26)-(g/67108864|0),this.words[b+h]=M&67108863}for(;b<this.length-h;b++)M=(this.words[b+h]|0)+P,P=M>>26,this.words[b+h]=M&67108863;if(P===0)return this._strip();for(t(P===-1),P=0,b=0;b<this.length;b++)M=-(this.words[b]|0)+P,P=M>>26,this.words[b]=M&67108863;return this.negative=1,this._strip()},e.prototype._wordDiv=function(o,u){var h=this.length-o.length,m=this.clone(),b=o,M=b.words[b.length-1]|0,P=this._countBits(M);h=26-P,h!==0&&(b=b.ushln(h),m.iushln(h),M=b.words[b.length-1]|0);var g=m.length-b.length,a;if(u!=="mod"){a=new e(null),a.length=g+1,a.words=new Array(a.length);for(var w=0;w<a.length;w++)a.words[w]=0}var R=m.clone()._ishlnsubmul(b,1,g);R.negative===0&&(m=R,a&&(a.words[g]=1));for(var D=g-1;D>=0;D--){var W=(m.words[b.length+D]|0)*67108864+(m.words[b.length+D-1]|0);for(W=Math.min(W/M|0,67108863),m._ishlnsubmul(b,W,D);m.negative!==0;)W--,m.negative=0,m._ishlnsubmul(b,1,D),m.isZero()||(m.negative^=1);a&&(a.words[D]=W)}return a&&a._strip(),m._strip(),u!=="div"&&h!==0&&m.iushrn(h),{div:a||null,mod:m}},e.prototype.divmod=function(o,u,h){if(t(!o.isZero()),this.isZero())return{div:new e(0),mod:new e(0)};var m,b,M;return this.negative!==0&&o.negative===0?(M=this.neg().divmod(o,u),u!=="mod"&&(m=M.div.neg()),u!=="div"&&(b=M.mod.neg(),h&&b.negative!==0&&b.iadd(o)),{div:m,mod:b}):this.negative===0&&o.negative!==0?(M=this.divmod(o.neg(),u),u!=="mod"&&(m=M.div.neg()),{div:m,mod:M.mod}):(this.negative&o.negative)!==0?(M=this.neg().divmod(o.neg(),u),u!=="div"&&(b=M.mod.neg(),h&&b.negative!==0&&b.isub(o)),{div:M.div,mod:b}):o.length>this.length||this.cmp(o)<0?{div:new e(0),mod:this}:o.length===1?u==="div"?{div:this.divn(o.words[0]),mod:null}:u==="mod"?{div:null,mod:new e(this.modrn(o.words[0]))}:{div:this.divn(o.words[0]),mod:new e(this.modrn(o.words[0]))}:this._wordDiv(o,u)},e.prototype.div=function(o){return this.divmod(o,"div",!1).div},e.prototype.mod=function(o){return this.divmod(o,"mod",!1).mod},e.prototype.umod=function(o){return this.divmod(o,"mod",!0).mod},e.prototype.divRound=function(o){var u=this.divmod(o);if(u.mod.isZero())return u.div;var h=u.div.negative!==0?u.mod.isub(o):u.mod,m=o.ushrn(1),b=o.andln(1),M=h.cmp(m);return M<0||b===1&&M===0?u.div:u.div.negative!==0?u.div.isubn(1):u.div.iaddn(1)},e.prototype.modrn=function(o){var u=o<0;u&&(o=-o),t(o<=67108863);for(var h=(1<<26)%o,m=0,b=this.length-1;b>=0;b--)m=(h*m+(this.words[b]|0))%o;return u?-m:m},e.prototype.modn=function(o){return this.modrn(o)},e.prototype.idivn=function(o){var u=o<0;u&&(o=-o),t(o<=67108863);for(var h=0,m=this.length-1;m>=0;m--){var b=(this.words[m]|0)+h*67108864;this.words[m]=b/o|0,h=b%o}return this._strip(),u?this.ineg():this},e.prototype.divn=function(o){return this.clone().idivn(o)},e.prototype.egcd=function(o){t(o.negative===0),t(!o.isZero());var u=this,h=o.clone();u.negative!==0?u=u.umod(o):u=u.clone();for(var m=new e(1),b=new e(0),M=new e(0),P=new e(1),g=0;u.isEven()&&h.isEven();)u.iushrn(1),h.iushrn(1),++g;for(var a=h.clone(),w=u.clone();!u.isZero();){for(var R=0,D=1;(u.words[0]&D)===0&&R<26;++R,D<<=1);if(R>0)for(u.iushrn(R);R-- >0;)(m.isOdd()||b.isOdd())&&(m.iadd(a),b.isub(w)),m.iushrn(1),b.iushrn(1);for(var W=0,z=1;(h.words[0]&z)===0&&W<26;++W,z<<=1);if(W>0)for(h.iushrn(W);W-- >0;)(M.isOdd()||P.isOdd())&&(M.iadd(a),P.isub(w)),M.iushrn(1),P.iushrn(1);u.cmp(h)>=0?(u.isub(h),m.isub(M),b.isub(P)):(h.isub(u),M.isub(m),P.isub(b))}return{a:M,b:P,gcd:h.iushln(g)}},e.prototype._invmp=function(o){t(o.negative===0),t(!o.isZero());var u=this,h=o.clone();u.negative!==0?u=u.umod(o):u=u.clone();for(var m=new e(1),b=new e(0),M=h.clone();u.cmpn(1)>0&&h.cmpn(1)>0;){for(var P=0,g=1;(u.words[0]&g)===0&&P<26;++P,g<<=1);if(P>0)for(u.iushrn(P);P-- >0;)m.isOdd()&&m.iadd(M),m.iushrn(1);for(var a=0,w=1;(h.words[0]&w)===0&&a<26;++a,w<<=1);if(a>0)for(h.iushrn(a);a-- >0;)b.isOdd()&&b.iadd(M),b.iushrn(1);u.cmp(h)>=0?(u.isub(h),m.isub(b)):(h.isub(u),b.isub(m))}var R;return u.cmpn(1)===0?R=m:R=b,R.cmpn(0)<0&&R.iadd(o),R},e.prototype.gcd=function(o){if(this.isZero())return o.abs();if(o.isZero())return this.abs();var u=this.clone(),h=o.clone();u.negative=0,h.negative=0;for(var m=0;u.isEven()&&h.isEven();m++)u.iushrn(1),h.iushrn(1);do{for(;u.isEven();)u.iushrn(1);for(;h.isEven();)h.iushrn(1);var b=u.cmp(h);if(b<0){var M=u;u=h,h=M}else if(b===0||h.cmpn(1)===0)break;u.isub(h)}while(!0);return h.iushln(m)},e.prototype.invm=function(o){return this.egcd(o).a.umod(o)},e.prototype.isEven=function(){return(this.words[0]&1)===0},e.prototype.isOdd=function(){return(this.words[0]&1)===1},e.prototype.andln=function(o){return this.words[0]&o},e.prototype.bincn=function(o){t(typeof o=="number");var u=o%26,h=(o-u)/26,m=1<<u;if(this.length<=h)return this._expand(h+1),this.words[h]|=m,this;for(var b=m,M=h;b!==0&&M<this.length;M++){var P=this.words[M]|0;P+=b,b=P>>>26,P&=67108863,this.words[M]=P}return b!==0&&(this.words[M]=b,this.length++),this},e.prototype.isZero=function(){return this.length===1&&this.words[0]===0},e.prototype.cmpn=function(o){var u=o<0;if(this.negative!==0&&!u)return-1;if(this.negative===0&&u)return 1;this._strip();var h;if(this.length>1)h=1;else{u&&(o=-o),t(o<=67108863,"Number is too big");var m=this.words[0]|0;h=m===o?0:m<o?-1:1}return this.negative!==0?-h|0:h},e.prototype.cmp=function(o){if(this.negative!==0&&o.negative===0)return-1;if(this.negative===0&&o.negative!==0)return 1;var u=this.ucmp(o);return this.negative!==0?-u|0:u},e.prototype.ucmp=function(o){if(this.length>o.length)return 1;if(this.length<o.length)return-1;for(var u=0,h=this.length-1;h>=0;h--){var m=this.words[h]|0,b=o.words[h]|0;if(m!==b){m<b?u=-1:m>b&&(u=1);break}}return u},e.prototype.gtn=function(o){return this.cmpn(o)===1},e.prototype.gt=function(o){return this.cmp(o)===1},e.prototype.gten=function(o){return this.cmpn(o)>=0},e.prototype.gte=function(o){return this.cmp(o)>=0},e.prototype.ltn=function(o){return this.cmpn(o)===-1},e.prototype.lt=function(o){return this.cmp(o)===-1},e.prototype.lten=function(o){return this.cmpn(o)<=0},e.prototype.lte=function(o){return this.cmp(o)<=0},e.prototype.eqn=function(o){return this.cmpn(o)===0},e.prototype.eq=function(o){return this.cmp(o)===0},e.red=function(o){return new G(o)},e.prototype.toRed=function(o){return t(!this.red,"Already a number in reduction context"),t(this.negative===0,"red works only with positives"),o.convertTo(this)._forceRed(o)},e.prototype.fromRed=function(){return t(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},e.prototype._forceRed=function(o){return this.red=o,this},e.prototype.forceRed=function(o){return t(!this.red,"Already a number in reduction context"),this._forceRed(o)},e.prototype.redAdd=function(o){return t(this.red,"redAdd works only with red numbers"),this.red.add(this,o)},e.prototype.redIAdd=function(o){return t(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,o)},e.prototype.redSub=function(o){return t(this.red,"redSub works only with red numbers"),this.red.sub(this,o)},e.prototype.redISub=function(o){return t(this.red,"redISub works only with red numbers"),this.red.isub(this,o)},e.prototype.redShl=function(o){return t(this.red,"redShl works only with red numbers"),this.red.shl(this,o)},e.prototype.redMul=function(o){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,o),this.red.mul(this,o)},e.prototype.redIMul=function(o){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,o),this.red.imul(this,o)},e.prototype.redSqr=function(){return t(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},e.prototype.redISqr=function(){return t(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},e.prototype.redSqrt=function(){return t(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},e.prototype.redInvm=function(){return t(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},e.prototype.redNeg=function(){return t(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},e.prototype.redPow=function(o){return t(this.red&&!o.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,o)};var j={k256:null,p224:null,p192:null,p25519:null};function N(v,o){this.name=v,this.p=new e(o,16),this.n=this.p.bitLength(),this.k=new e(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}N.prototype._tmp=function(){var o=new e(null);return o.words=new Array(Math.ceil(this.n/13)),o},N.prototype.ireduce=function(o){var u=o,h;do this.split(u,this.tmp),u=this.imulK(u),u=u.iadd(this.tmp),h=u.bitLength();while(h>this.n);var m=h<this.n?-1:u.ucmp(this.p);return m===0?(u.words[0]=0,u.length=1):m>0?u.isub(this.p):u.strip!==void 0?u.strip():u._strip(),u},N.prototype.split=function(o,u){o.iushrn(this.n,0,u)},N.prototype.imulK=function(o){return o.imul(this.k)};function X(){N.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}r(X,N),X.prototype.split=function(o,u){for(var h=4194303,m=Math.min(o.length,9),b=0;b<m;b++)u.words[b]=o.words[b];if(u.length=m,o.length<=9){o.words[0]=0,o.length=1;return}var M=o.words[9];for(u.words[u.length++]=M&h,b=10;b<o.length;b++){var P=o.words[b]|0;o.words[b-10]=(P&h)<<4|M>>>22,M=P}M>>>=22,o.words[b-10]=M,M===0&&o.length>10?o.length-=10:o.length-=9},X.prototype.imulK=function(o){o.words[o.length]=0,o.words[o.length+1]=0,o.length+=2;for(var u=0,h=0;h<o.length;h++){var m=o.words[h]|0;u+=m*977,o.words[h]=u&67108863,u=m*64+(u/67108864|0)}return o.words[o.length-1]===0&&(o.length--,o.words[o.length-1]===0&&o.length--),o};function tt(){N.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}r(tt,N);function it(){N.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}r(it,N);function st(){N.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}r(st,N),st.prototype.imulK=function(o){for(var u=0,h=0;h<o.length;h++){var m=(o.words[h]|0)*19+u,b=m&67108863;m>>>=26,o.words[h]=b,u=m}return u!==0&&(o.words[o.length++]=u),o},e._prime=function(o){if(j[o])return j[o];var u;if(o==="k256")u=new X;else if(o==="p224")u=new tt;else if(o==="p192")u=new it;else if(o==="p25519")u=new st;else throw new Error("Unknown prime "+o);return j[o]=u,u};function G(v){if(typeof v=="string"){var o=e._prime(v);this.m=o.p,this.prime=o}else t(v.gtn(1),"modulus must be greater than 1"),this.m=v,this.prime=null}G.prototype._verify1=function(o){t(o.negative===0,"red works only with positives"),t(o.red,"red works only with red numbers")},G.prototype._verify2=function(o,u){t((o.negative|u.negative)===0,"red works only with positives"),t(o.red&&o.red===u.red,"red works only with red numbers")},G.prototype.imod=function(o){return this.prime?this.prime.ireduce(o)._forceRed(this):(c(o,o.umod(this.m)._forceRed(this)),o)},G.prototype.neg=function(o){return o.isZero()?o.clone():this.m.sub(o)._forceRed(this)},G.prototype.add=function(o,u){this._verify2(o,u);var h=o.add(u);return h.cmp(this.m)>=0&&h.isub(this.m),h._forceRed(this)},G.prototype.iadd=function(o,u){this._verify2(o,u);var h=o.iadd(u);return h.cmp(this.m)>=0&&h.isub(this.m),h},G.prototype.sub=function(o,u){this._verify2(o,u);var h=o.sub(u);return h.cmpn(0)<0&&h.iadd(this.m),h._forceRed(this)},G.prototype.isub=function(o,u){this._verify2(o,u);var h=o.isub(u);return h.cmpn(0)<0&&h.iadd(this.m),h},G.prototype.shl=function(o,u){return this._verify1(o),this.imod(o.ushln(u))},G.prototype.imul=function(o,u){return this._verify2(o,u),this.imod(o.imul(u))},G.prototype.mul=function(o,u){return this._verify2(o,u),this.imod(o.mul(u))},G.prototype.isqr=function(o){return this.imul(o,o.clone())},G.prototype.sqr=function(o){return this.mul(o,o)},G.prototype.sqrt=function(o){if(o.isZero())return o.clone();var u=this.m.andln(3);if(t(u%2===1),u===3){var h=this.m.add(new e(1)).iushrn(2);return this.pow(o,h)}for(var m=this.m.subn(1),b=0;!m.isZero()&&m.andln(1)===0;)b++,m.iushrn(1);t(!m.isZero());var M=new e(1).toRed(this),P=M.redNeg(),g=this.m.subn(1).iushrn(1),a=this.m.bitLength();for(a=new e(2*a*a).toRed(this);this.pow(a,g).cmp(P)!==0;)a.redIAdd(P);for(var w=this.pow(a,m),R=this.pow(o,m.addn(1).iushrn(1)),D=this.pow(o,m),W=b;D.cmp(M)!==0;){for(var z=D,J=0;z.cmp(M)!==0;J++)z=z.redSqr();t(J<W);var L=this.pow(w,new e(1).iushln(W-J-1));R=R.redMul(L),w=L.redSqr(),D=D.redMul(w),W=J}return R},G.prototype.invm=function(o){var u=o._invmp(this.m);return u.negative!==0?(u.negative=0,this.imod(u).redNeg()):this.imod(u)},G.prototype.pow=function(o,u){if(u.isZero())return new e(1).toRed(this);if(u.cmpn(1)===0)return o.clone();var h=4,m=new Array(1<<h);m[0]=new e(1).toRed(this),m[1]=o;for(var b=2;b<m.length;b++)m[b]=this.mul(m[b-1],o);var M=m[0],P=0,g=0,a=u.bitLength()%26;for(a===0&&(a=26),b=u.length-1;b>=0;b--){for(var w=u.words[b],R=a-1;R>=0;R--){var D=w>>R&1;if(M!==m[0]&&(M=this.sqr(M)),D===0&&P===0){g=0;continue}P<<=1,P|=D,g++,!(g!==h&&(b!==0||R!==0))&&(M=this.mul(M,m[P]),g=0,P=0)}a=26}return M},G.prototype.convertTo=function(o){var u=o.umod(this.m);return u===o?u.clone():u},G.prototype.convertFrom=function(o){var u=o.clone();return u.red=null,u},e.mont=function(o){return new nt(o)};function nt(v){G.call(this,v),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new e(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)}r(nt,G),nt.prototype.convertTo=function(o){return this.imod(o.ushln(this.shift))},nt.prototype.convertFrom=function(o){var u=this.imod(o.mul(this.rinv));return u.red=null,u},nt.prototype.imul=function(o,u){if(o.isZero()||u.isZero())return o.words[0]=0,o.length=1,o;var h=o.imul(u),m=h.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),b=h.isub(m).iushrn(this.shift),M=b;return b.cmp(this.m)>=0?M=b.isub(this.m):b.cmpn(0)<0&&(M=b.iadd(this.m)),M._forceRed(this)},nt.prototype.mul=function(o,u){if(o.isZero()||u.isZero())return new e(0)._forceRed(this);var h=o.mul(u),m=h.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),b=h.isub(m).iushrn(this.shift),M=b;return b.cmp(this.m)>=0?M=b.isub(this.m):b.cmpn(0)<0&&(M=b.iadd(this.m)),M._forceRed(this)},nt.prototype.invm=function(o){var u=this.imod(o._invmp(this.m).mul(this.r2));return u._forceRed(this)}})(typeof Pi>"u"||Pi,lr)});import{SdkWrapper as Po}from"@cetusprotocol/common-sdk";import{FullRpcUrlMainnet as on,GraphRpcUrlMainnet as sn}from"@cetusprotocol/common-sdk";var ar={env:"mainnet",full_rpc_url:on,graph_rpc_url:sn,dlmm_pool:{package_id:"0x5664f9d3fd82c84023870cfbda8ea84e14c8dd56ce557ad2116e0668581a682b",published_at:"0x44d0fb760f9f7ce532a4a97abddf2e7982c9b9b50ac94cf62de8f4d11356d306",version:5,config:{registry_id:"0xb1d55e7d895823c65f98d99b81a69436cf7d1638629c9ccb921326039cda1f1b",pools_id:"0xc3683b2356cac6423e9ecaea20955c7cc193998b016e5b884730ed1192174991",global_config_id:"0xf31b605d117f959b9730e8c07b08b856cb05143c5e81d5751c90d2979e82f599",versioned_id:"0x05370b2d656612dd5759cbe80463de301e3b94a921dfc72dd9daa2ecdeb2d0a8",admin_cap_id:"0xc4c42bc31cb54beb679dccd547f8bdb970cb6dc989bd1f85a4fed4812ed95d6e",partners_id:"0x5c0affc8d363b6abb1f32790c229165215f4edead89a9bc7cd95dad717b4296a"}},dlmm_router:{package_id:"0x8d389fa25cb08ebc5e520bc520ed394eed9e62b56b7868acb398bf298b8a76f3",published_at:"0xdb974d2654a62bb0668f58ee7919b5e41566a6c3336c3a006a412d5137487c67",version:3}};import{Transaction as Ke}from"@mysten/sui/transactions";import{asUintN as Fr,CLOCK_ADDRESS as so,createFullClient as ao,d as Ni,deriveDynamicFieldIdByType as lo,DETAILS_KEYS as te,fixCoinType as Nr,getObjectFields as Lr,getPackagerConfigs as qr,isSortedSymbols as uo}from"@cetusprotocol/common-sdk";import{BaseError as an}from"@cetusprotocol/common-sdk";var ge=class extends an{constructor(i,t,r){super(i,t||"UnknownError",r)}static isDlmmErrorCode(i,t){return this.isErrorCode(i,t)}},V=(n,i,t)=>{let r={...t,stack:i instanceof Error?i.stack:void 0};throw i instanceof Error?new ge(i.message,n,r):new ge(i,n,r)};var Sr=Mi(xe());import{asIntN as Ae,d as Ci,DETAILS_KEYS as pe,extractStructTagFromType as ki,fixCoinType as ne,getObjectFields as xi,getObjectType as Br,MathUtil as ro}from"@cetusprotocol/common-sdk";var we=9e15,fe=1e9,Ai="0123456789abcdef",Fe="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Ne="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Bi={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-we,maxE:we,crypto:!1},cr,se,$=!0,qe="[DecimalError] ",de=qe+"Invalid argument: ",hr=qe+"Precision limit exceeded",pr=qe+"crypto unavailable",mr="[object Decimal]",Kt=Math.floor,Ut=Math.pow,ln=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,un=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,dn=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,_r=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Xt=1e7,Q=7,fn=9007199254740991,cn=Fe.length-1,Si=Ne.length-1,I={toStringTag:mr};I.absoluteValue=I.abs=function(){var n=new this.constructor(this);return n.s<0&&(n.s=1),U(n)};I.ceil=function(){return U(new this.constructor(this),this.e+1,2)};I.clampedTo=I.clamp=function(n,i){var t,r=this,e=r.constructor;if(n=new e(n),i=new e(i),!n.s||!i.s)return new e(NaN);if(n.gt(i))throw Error(de+i);return t=r.cmp(n),t<0?n:r.cmp(i)>0?i:new e(r)};I.comparedTo=I.cmp=function(n){var i,t,r,e,s=this,l=s.d,d=(n=new s.constructor(n)).d,f=s.s,c=n.s;if(!l||!d)return!f||!c?NaN:f!==c?f:l===d?0:!l^f<0?1:-1;if(!l[0]||!d[0])return l[0]?f:d[0]?-c:0;if(f!==c)return f;if(s.e!==n.e)return s.e>n.e^f<0?1:-1;for(r=l.length,e=d.length,i=0,t=r<e?r:e;i<t;++i)if(l[i]!==d[i])return l[i]>d[i]^f<0?1:-1;return r===e?0:r>e^f<0?1:-1};I.cosine=I.cos=function(){var n,i,t=this,r=t.constructor;return t.d?t.d[0]?(n=r.precision,i=r.rounding,r.precision=n+Math.max(t.e,t.sd())+Q,r.rounding=1,t=hn(r,yr(r,t)),r.precision=n,r.rounding=i,U(se==2||se==3?t.neg():t,n,i,!0)):new r(1):new r(NaN)};I.cubeRoot=I.cbrt=function(){var n,i,t,r,e,s,l,d,f,c,p=this,_=p.constructor;if(!p.isFinite()||p.isZero())return new _(p);for($=!1,s=p.s*Ut(p.s*p,1/3),!s||Math.abs(s)==1/0?(t=Qt(p.d),n=p.e,(s=(n-t.length+1)%3)&&(t+=s==1||s==-2?"0":"00"),s=Ut(t,1/3),n=Kt((n+1)/3)-(n%3==(n<0?-1:2)),s==1/0?t="5e"+n:(t=s.toExponential(),t=t.slice(0,t.indexOf("e")+1)+n),r=new _(t),r.s=p.s):r=new _(s.toString()),l=(n=_.precision)+3;;)if(d=r,f=d.times(d).times(d),c=f.plus(p),r=ot(c.plus(p).times(d),c.plus(f),l+2,1),Qt(d.d).slice(0,l)===(t=Qt(r.d)).slice(0,l))if(t=t.slice(l-3,l+1),t=="9999"||!e&&t=="4999"){if(!e&&(U(d,n+1,0),d.times(d).times(d).eq(p))){r=d;break}l+=4,e=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(U(r,n+1,1),i=!r.times(r).times(r).eq(p));break}return $=!0,U(r,n,_.rounding,i)};I.decimalPlaces=I.dp=function(){var n,i=this.d,t=NaN;if(i){if(n=i.length-1,t=(n-Kt(this.e/Q))*Q,n=i[n],n)for(;n%10==0;n/=10)t--;t<0&&(t=0)}return t};I.dividedBy=I.div=function(n){return ot(this,new this.constructor(n))};I.dividedToIntegerBy=I.divToInt=function(n){var i=this,t=i.constructor;return U(ot(i,new t(n),0,1,1),t.precision,t.rounding)};I.equals=I.eq=function(n){return this.cmp(n)===0};I.floor=function(){return U(new this.constructor(this),this.e+1,3)};I.greaterThan=I.gt=function(n){return this.cmp(n)>0};I.greaterThanOrEqualTo=I.gte=function(n){var i=this.cmp(n);return i==1||i===0};I.hyperbolicCosine=I.cosh=function(){var n,i,t,r,e,s=this,l=s.constructor,d=new l(1);if(!s.isFinite())return new l(s.s?1/0:NaN);if(s.isZero())return d;t=l.precision,r=l.rounding,l.precision=t+Math.max(s.e,s.sd())+4,l.rounding=1,e=s.d.length,e<32?(n=Math.ceil(e/3),i=(1/We(4,n)).toString()):(n=16,i="2.3283064365386962890625e-10"),s=ve(l,1,s.times(i),new l(1),!0);for(var f,c=n,p=new l(8);c--;)f=s.times(s),s=d.minus(f.times(p.minus(f.times(p))));return U(s,l.precision=t,l.rounding=r,!0)};I.hyperbolicSine=I.sinh=function(){var n,i,t,r,e=this,s=e.constructor;if(!e.isFinite()||e.isZero())return new s(e);if(i=s.precision,t=s.rounding,s.precision=i+Math.max(e.e,e.sd())+4,s.rounding=1,r=e.d.length,r<3)e=ve(s,2,e,e,!0);else{n=1.4*Math.sqrt(r),n=n>16?16:n|0,e=e.times(1/We(5,n)),e=ve(s,2,e,e,!0);for(var l,d=new s(5),f=new s(16),c=new s(20);n--;)l=e.times(e),e=e.times(d.plus(l.times(f.times(l).plus(c))))}return s.precision=i,s.rounding=t,U(e,i,t,!0)};I.hyperbolicTangent=I.tanh=function(){var n,i,t=this,r=t.constructor;return t.isFinite()?t.isZero()?new r(t):(n=r.precision,i=r.rounding,r.precision=n+7,r.rounding=1,ot(t.sinh(),t.cosh(),r.precision=n,r.rounding=i)):new r(t.s)};I.inverseCosine=I.acos=function(){var n=this,i=n.constructor,t=n.abs().cmp(1),r=i.precision,e=i.rounding;return t!==-1?t===0?n.isNeg()?ie(i,r,e):new i(0):new i(NaN):n.isZero()?ie(i,r+4,e).times(.5):(i.precision=r+6,i.rounding=1,n=new i(1).minus(n).div(n.plus(1)).sqrt().atan(),i.precision=r,i.rounding=e,n.times(2))};I.inverseHyperbolicCosine=I.acosh=function(){var n,i,t=this,r=t.constructor;return t.lte(1)?new r(t.eq(1)?0:NaN):t.isFinite()?(n=r.precision,i=r.rounding,r.precision=n+Math.max(Math.abs(t.e),t.sd())+4,r.rounding=1,$=!1,t=t.times(t).minus(1).sqrt().plus(t),$=!0,r.precision=n,r.rounding=i,t.ln()):new r(t)};I.inverseHyperbolicSine=I.asinh=function(){var n,i,t=this,r=t.constructor;return!t.isFinite()||t.isZero()?new r(t):(n=r.precision,i=r.rounding,r.precision=n+2*Math.max(Math.abs(t.e),t.sd())+6,r.rounding=1,$=!1,t=t.times(t).plus(1).sqrt().plus(t),$=!0,r.precision=n,r.rounding=i,t.ln())};I.inverseHyperbolicTangent=I.atanh=function(){var n,i,t,r,e=this,s=e.constructor;return e.isFinite()?e.e>=0?new s(e.abs().eq(1)?e.s/0:e.isZero()?e:NaN):(n=s.precision,i=s.rounding,r=e.sd(),Math.max(r,n)<2*-e.e-1?U(new s(e),n,i,!0):(s.precision=t=r-e.e,e=ot(e.plus(1),new s(1).minus(e),t+n,1),s.precision=n+4,s.rounding=1,e=e.ln(),s.precision=n,s.rounding=i,e.times(.5))):new s(NaN)};I.inverseSine=I.asin=function(){var n,i,t,r,e=this,s=e.constructor;return e.isZero()?new s(e):(i=e.abs().cmp(1),t=s.precision,r=s.rounding,i!==-1?i===0?(n=ie(s,t+4,r).times(.5),n.s=e.s,n):new s(NaN):(s.precision=t+6,s.rounding=1,e=e.div(new s(1).minus(e.times(e)).sqrt().plus(1)).atan(),s.precision=t,s.rounding=r,e.times(2)))};I.inverseTangent=I.atan=function(){var n,i,t,r,e,s,l,d,f,c=this,p=c.constructor,_=p.precision,y=p.rounding;if(c.isFinite()){if(c.isZero())return new p(c);if(c.abs().eq(1)&&_+4<=Si)return l=ie(p,_+4,y).times(.25),l.s=c.s,l}else{if(!c.s)return new p(NaN);if(_+4<=Si)return l=ie(p,_+4,y).times(.5),l.s=c.s,l}for(p.precision=d=_+10,p.rounding=1,t=Math.min(28,d/Q+2|0),n=t;n;--n)c=c.div(c.times(c).plus(1).sqrt().plus(1));for($=!1,i=Math.ceil(d/Q),r=1,f=c.times(c),l=new p(c),e=c;n!==-1;)if(e=e.times(f),s=l.minus(e.div(r+=2)),e=e.times(f),l=s.plus(e.div(r+=2)),l.d[i]!==void 0)for(n=i;l.d[n]===s.d[n]&&n--;);return t&&(l=l.times(2<<t-1)),$=!0,U(l,p.precision=_,p.rounding=y,!0)};I.isFinite=function(){return!!this.d};I.isInteger=I.isInt=function(){return!!this.d&&Kt(this.e/Q)>this.d.length-2};I.isNaN=function(){return!this.s};I.isNegative=I.isNeg=function(){return this.s<0};I.isPositive=I.isPos=function(){return this.s>0};I.isZero=function(){return!!this.d&&this.d[0]===0};I.lessThan=I.lt=function(n){return this.cmp(n)<0};I.lessThanOrEqualTo=I.lte=function(n){return this.cmp(n)<1};I.logarithm=I.log=function(n){var i,t,r,e,s,l,d,f,c=this,p=c.constructor,_=p.precision,y=p.rounding,A=5;if(n==null)n=new p(10),i=!0;else{if(n=new p(n),t=n.d,n.s<0||!t||!t[0]||n.eq(1))return new p(NaN);i=n.eq(10)}if(t=c.d,c.s<0||!t||!t[0]||c.eq(1))return new p(t&&!t[0]?-1/0:c.s!=1?NaN:t?0:1/0);if(i)if(t.length>1)s=!0;else{for(e=t[0];e%10===0;)e/=10;s=e!==1}if($=!1,d=_+A,l=ue(c,d),r=i?Le(p,d+10):ue(n,d),f=ot(l,r,d,1),Ie(f.d,e=_,y))do if(d+=10,l=ue(c,d),r=i?Le(p,d+10):ue(n,d),f=ot(l,r,d,1),!s){+Qt(f.d).slice(e+1,e+15)+1==1e14&&(f=U(f,_+1,0));break}while(Ie(f.d,e+=10,y));return $=!0,U(f,_,y)};I.minus=I.sub=function(n){var i,t,r,e,s,l,d,f,c,p,_,y,A=this,B=A.constructor;if(n=new B(n),!A.d||!n.d)return!A.s||!n.s?n=new B(NaN):A.d?n.s=-n.s:n=new B(n.d||A.s!==n.s?A:NaN),n;if(A.s!=n.s)return n.s=-n.s,A.plus(n);if(c=A.d,y=n.d,d=B.precision,f=B.rounding,!c[0]||!y[0]){if(y[0])n.s=-n.s;else if(c[0])n=new B(A);else return new B(f===3?-0:0);return $?U(n,d,f):n}if(t=Kt(n.e/Q),p=Kt(A.e/Q),c=c.slice(),s=p-t,s){for(_=s<0,_?(i=c,s=-s,l=y.length):(i=y,t=p,l=c.length),r=Math.max(Math.ceil(d/Q),l)+2,s>r&&(s=r,i.length=1),i.reverse(),r=s;r--;)i.push(0);i.reverse()}else{for(r=c.length,l=y.length,_=r<l,_&&(l=r),r=0;r<l;r++)if(c[r]!=y[r]){_=c[r]<y[r];break}s=0}for(_&&(i=c,c=y,y=i,n.s=-n.s),l=c.length,r=y.length-l;r>0;--r)c[l++]=0;for(r=y.length;r>s;){if(c[--r]<y[r]){for(e=r;e&&c[--e]===0;)c[e]=Xt-1;--c[e],c[r]+=Xt}c[r]-=y[r]}for(;c[--l]===0;)c.pop();for(;c[0]===0;c.shift())--t;return c[0]?(n.d=c,n.e=je(c,t),$?U(n,d,f):n):new B(f===3?-0:0)};I.modulo=I.mod=function(n){var i,t=this,r=t.constructor;return n=new r(n),!t.d||!n.s||n.d&&!n.d[0]?new r(NaN):!n.d||t.d&&!t.d[0]?U(new r(t),r.precision,r.rounding):($=!1,r.modulo==9?(i=ot(t,n.abs(),0,3,1),i.s*=n.s):i=ot(t,n,0,r.modulo,1),i=i.times(n),$=!0,t.minus(i))};I.naturalExponential=I.exp=function(){return Ii(this)};I.naturalLogarithm=I.ln=function(){return ue(this)};I.negated=I.neg=function(){var n=new this.constructor(this);return n.s=-n.s,U(n)};I.plus=I.add=function(n){var i,t,r,e,s,l,d,f,c,p,_=this,y=_.constructor;if(n=new y(n),!_.d||!n.d)return!_.s||!n.s?n=new y(NaN):_.d||(n=new y(n.d||_.s===n.s?_:NaN)),n;if(_.s!=n.s)return n.s=-n.s,_.minus(n);if(c=_.d,p=n.d,d=y.precision,f=y.rounding,!c[0]||!p[0])return p[0]||(n=new y(_)),$?U(n,d,f):n;if(s=Kt(_.e/Q),r=Kt(n.e/Q),c=c.slice(),e=s-r,e){for(e<0?(t=c,e=-e,l=p.length):(t=p,r=s,l=c.length),s=Math.ceil(d/Q),l=s>l?s+1:l+1,e>l&&(e=l,t.length=1),t.reverse();e--;)t.push(0);t.reverse()}for(l=c.length,e=p.length,l-e<0&&(e=l,t=p,p=c,c=t),i=0;e;)i=(c[--e]=c[e]+p[e]+i)/Xt|0,c[e]%=Xt;for(i&&(c.unshift(i),++r),l=c.length;c[--l]==0;)c.pop();return n.d=c,n.e=je(c,r),$?U(n,d,f):n};I.precision=I.sd=function(n){var i,t=this;if(n!==void 0&&n!==!!n&&n!==1&&n!==0)throw Error(de+n);return t.d?(i=gr(t.d),n&&t.e+1>i&&(i=t.e+1)):i=NaN,i};I.round=function(){var n=this,i=n.constructor;return U(new i(n),n.e+1,i.rounding)};I.sine=I.sin=function(){var n,i,t=this,r=t.constructor;return t.isFinite()?t.isZero()?new r(t):(n=r.precision,i=r.rounding,r.precision=n+Math.max(t.e,t.sd())+Q,r.rounding=1,t=mn(r,yr(r,t)),r.precision=n,r.rounding=i,U(se>2?t.neg():t,n,i,!0)):new r(NaN)};I.squareRoot=I.sqrt=function(){var n,i,t,r,e,s,l=this,d=l.d,f=l.e,c=l.s,p=l.constructor;if(c!==1||!d||!d[0])return new p(!c||c<0&&(!d||d[0])?NaN:d?l:1/0);for($=!1,c=Math.sqrt(+l),c==0||c==1/0?(i=Qt(d),(i.length+f)%2==0&&(i+="0"),c=Math.sqrt(i),f=Kt((f+1)/2)-(f<0||f%2),c==1/0?i="5e"+f:(i=c.toExponential(),i=i.slice(0,i.indexOf("e")+1)+f),r=new p(i)):r=new p(c.toString()),t=(f=p.precision)+3;;)if(s=r,r=s.plus(ot(l,s,t+2,1)).times(.5),Qt(s.d).slice(0,t)===(i=Qt(r.d)).slice(0,t))if(i=i.slice(t-3,t+1),i=="9999"||!e&&i=="4999"){if(!e&&(U(s,f+1,0),s.times(s).eq(l))){r=s;break}t+=4,e=1}else{(!+i||!+i.slice(1)&&i.charAt(0)=="5")&&(U(r,f+1,1),n=!r.times(r).eq(l));break}return $=!0,U(r,f,p.rounding,n)};I.tangent=I.tan=function(){var n,i,t=this,r=t.constructor;return t.isFinite()?t.isZero()?new r(t):(n=r.precision,i=r.rounding,r.precision=n+10,r.rounding=1,t=t.sin(),t.s=1,t=ot(t,new r(1).minus(t.times(t)).sqrt(),n+10,0),r.precision=n,r.rounding=i,U(se==2||se==4?t.neg():t,n,i,!0)):new r(NaN)};I.times=I.mul=function(n){var i,t,r,e,s,l,d,f,c,p=this,_=p.constructor,y=p.d,A=(n=new _(n)).d;if(n.s*=p.s,!y||!y[0]||!A||!A[0])return new _(!n.s||y&&!y[0]&&!A||A&&!A[0]&&!y?NaN:!y||!A?n.s/0:n.s*0);for(t=Kt(p.e/Q)+Kt(n.e/Q),f=y.length,c=A.length,f<c&&(s=y,y=A,A=s,l=f,f=c,c=l),s=[],l=f+c,r=l;r--;)s.push(0);for(r=c;--r>=0;){for(i=0,e=f+r;e>r;)d=s[e]+A[r]*y[e-r-1]+i,s[e--]=d%Xt|0,i=d/Xt|0;s[e]=(s[e]+i)%Xt|0}for(;!s[--l];)s.pop();return i?++t:s.shift(),n.d=s,n.e=je(s,t),$?U(n,_.precision,_.rounding):n};I.toBinary=function(n,i){return Ei(this,2,n,i)};I.toDecimalPlaces=I.toDP=function(n,i){var t=this,r=t.constructor;return t=new r(t),n===void 0?t:($t(n,0,fe),i===void 0?i=r.rounding:$t(i,0,8),U(t,n+t.e+1,i))};I.toExponential=function(n,i){var t,r=this,e=r.constructor;return n===void 0?t=re(r,!0):($t(n,0,fe),i===void 0?i=e.rounding:$t(i,0,8),r=U(new e(r),n+1,i),t=re(r,!0,n+1)),r.isNeg()&&!r.isZero()?"-"+t:t};I.toFixed=function(n,i){var t,r,e=this,s=e.constructor;return n===void 0?t=re(e):($t(n,0,fe),i===void 0?i=s.rounding:$t(i,0,8),r=U(new s(e),n+e.e+1,i),t=re(r,!1,n+r.e+1)),e.isNeg()&&!e.isZero()?"-"+t:t};I.toFraction=function(n){var i,t,r,e,s,l,d,f,c,p,_,y,A=this,B=A.d,S=A.constructor;if(!B)return new S(A);if(c=t=new S(1),r=f=new S(0),i=new S(r),s=i.e=gr(B)-A.e-1,l=s%Q,i.d[0]=Ut(10,l<0?Q+l:l),n==null)n=s>0?i:c;else{if(d=new S(n),!d.isInt()||d.lt(c))throw Error(de+d);n=d.gt(i)?s>0?i:c:d}for($=!1,d=new S(Qt(B)),p=S.precision,S.precision=s=B.length*Q*2;_=ot(d,i,0,1,1),e=t.plus(_.times(r)),e.cmp(n)!=1;)t=r,r=e,e=c,c=f.plus(_.times(e)),f=e,e=i,i=d.minus(_.times(e)),d=e;return e=ot(n.minus(t),r,0,1,1),f=f.plus(e.times(c)),t=t.plus(e.times(r)),f.s=c.s=A.s,y=ot(c,r,s,1).minus(A).abs().cmp(ot(f,t,s,1).minus(A).abs())<1?[c,r]:[f,t],S.precision=p,$=!0,y};I.toHexadecimal=I.toHex=function(n,i){return Ei(this,16,n,i)};I.toNearest=function(n,i){var t=this,r=t.constructor;if(t=new r(t),n==null){if(!t.d)return t;n=new r(1),i=r.rounding}else{if(n=new r(n),i===void 0?i=r.rounding:$t(i,0,8),!t.d)return n.s?t:n;if(!n.d)return n.s&&(n.s=t.s),n}return n.d[0]?($=!1,t=ot(t,n,0,i,1).times(n),$=!0,U(t)):(n.s=t.s,t=n),t};I.toNumber=function(){return+this};I.toOctal=function(n,i){return Ei(this,8,n,i)};I.toPower=I.pow=function(n){var i,t,r,e,s,l,d=this,f=d.constructor,c=+(n=new f(n));if(!d.d||!n.d||!d.d[0]||!n.d[0])return new f(Ut(+d,c));if(d=new f(d),d.eq(1))return d;if(r=f.precision,s=f.rounding,n.eq(1))return U(d,r,s);if(i=Kt(n.e/Q),i>=n.d.length-1&&(t=c<0?-c:c)<=fn)return e=br(f,d,t,r),n.s<0?new f(1).div(e):U(e,r,s);if(l=d.s,l<0){if(i<n.d.length-1)return new f(NaN);if((n.d[i]&1)==0&&(l=1),d.e==0&&d.d[0]==1&&d.d.length==1)return d.s=l,d}return t=Ut(+d,c),i=t==0||!isFinite(t)?Kt(c*(Math.log("0."+Qt(d.d))/Math.LN10+d.e+1)):new f(t+"").e,i>f.maxE+1||i<f.minE-1?new f(i>0?l/0:0):($=!1,f.rounding=d.s=1,t=Math.min(12,(i+"").length),e=Ii(n.times(ue(d,r+t)),r),e.d&&(e=U(e,r+5,1),Ie(e.d,r,s)&&(i=r+10,e=U(Ii(n.times(ue(d,i+t)),i),i+5,1),+Qt(e.d).slice(r+1,r+15)+1==1e14&&(e=U(e,r+1,0)))),e.s=l,$=!0,f.rounding=s,U(e,r,s))};I.toPrecision=function(n,i){var t,r=this,e=r.constructor;return n===void 0?t=re(r,r.e<=e.toExpNeg||r.e>=e.toExpPos):($t(n,1,fe),i===void 0?i=e.rounding:$t(i,0,8),r=U(new e(r),n,i),t=re(r,n<=r.e||r.e<=e.toExpNeg,n)),r.isNeg()&&!r.isZero()?"-"+t:t};I.toSignificantDigits=I.toSD=function(n,i){var t=this,r=t.constructor;return n===void 0?(n=r.precision,i=r.rounding):($t(n,1,fe),i===void 0?i=r.rounding:$t(i,0,8)),U(new r(t),n,i)};I.toString=function(){var n=this,i=n.constructor,t=re(n,n.e<=i.toExpNeg||n.e>=i.toExpPos);return n.isNeg()&&!n.isZero()?"-"+t:t};I.truncated=I.trunc=function(){return U(new this.constructor(this),this.e+1,1)};I.valueOf=I.toJSON=function(){var n=this,i=n.constructor,t=re(n,n.e<=i.toExpNeg||n.e>=i.toExpPos);return n.isNeg()?"-"+t:t};function Qt(n){var i,t,r,e=n.length-1,s="",l=n[0];if(e>0){for(s+=l,i=1;i<e;i++)r=n[i]+"",t=Q-r.length,t&&(s+=le(t)),s+=r;l=n[i],r=l+"",t=Q-r.length,t&&(s+=le(t))}else if(l===0)return"0";for(;l%10===0;)l/=10;return s+l}function $t(n,i,t){if(n!==~~n||n<i||n>t)throw Error(de+n)}function Ie(n,i,t,r){var e,s,l,d;for(s=n[0];s>=10;s/=10)--i;return--i<0?(i+=Q,e=0):(e=Math.ceil((i+1)/Q),i%=Q),s=Ut(10,Q-i),d=n[e]%s|0,r==null?i<3?(i==0?d=d/100|0:i==1&&(d=d/10|0),l=t<4&&d==99999||t>3&&d==49999||d==5e4||d==0):l=(t<4&&d+1==s||t>3&&d+1==s/2)&&(n[e+1]/s/100|0)==Ut(10,i-2)-1||(d==s/2||d==0)&&(n[e+1]/s/100|0)==0:i<4?(i==0?d=d/1e3|0:i==1?d=d/100|0:i==2&&(d=d/10|0),l=(r||t<4)&&d==9999||!r&&t>3&&d==4999):l=((r||t<4)&&d+1==s||!r&&t>3&&d+1==s/2)&&(n[e+1]/s/1e3|0)==Ut(10,i-3)-1,l}function Re(n,i,t){for(var r,e=[0],s,l=0,d=n.length;l<d;){for(s=e.length;s--;)e[s]*=i;for(e[0]+=Ai.indexOf(n.charAt(l++)),r=0;r<e.length;r++)e[r]>t-1&&(e[r+1]===void 0&&(e[r+1]=0),e[r+1]+=e[r]/t|0,e[r]%=t)}return e.reverse()}function hn(n,i){var t,r,e;if(i.isZero())return i;r=i.d.length,r<32?(t=Math.ceil(r/3),e=(1/We(4,t)).toString()):(t=16,e="2.3283064365386962890625e-10"),n.precision+=t,i=ve(n,1,i.times(e),new n(1));for(var s=t;s--;){var l=i.times(i);i=l.times(l).minus(l).times(8).plus(1)}return n.precision-=t,i}var ot=(function(){function n(r,e,s){var l,d=0,f=r.length;for(r=r.slice();f--;)l=r[f]*e+d,r[f]=l%s|0,d=l/s|0;return d&&r.unshift(d),r}function i(r,e,s,l){var d,f;if(s!=l)f=s>l?1:-1;else for(d=f=0;d<s;d++)if(r[d]!=e[d]){f=r[d]>e[d]?1:-1;break}return f}function t(r,e,s,l){for(var d=0;s--;)r[s]-=d,d=r[s]<e[s]?1:0,r[s]=d*l+r[s]-e[s];for(;!r[0]&&r.length>1;)r.shift()}return function(r,e,s,l,d,f){var c,p,_,y,A,B,S,O,k,x,T,C,j,N,X,tt,it,st,G,nt,v=r.constructor,o=r.s==e.s?1:-1,u=r.d,h=e.d;if(!u||!u[0]||!h||!h[0])return new v(!r.s||!e.s||(u?h&&u[0]==h[0]:!h)?NaN:u&&u[0]==0||!h?o*0:o/0);for(f?(A=1,p=r.e-e.e):(f=Xt,A=Q,p=Kt(r.e/A)-Kt(e.e/A)),G=h.length,it=u.length,k=new v(o),x=k.d=[],_=0;h[_]==(u[_]||0);_++);if(h[_]>(u[_]||0)&&p--,s==null?(N=s=v.precision,l=v.rounding):d?N=s+(r.e-e.e)+1:N=s,N<0)x.push(1),B=!0;else{if(N=N/A+2|0,_=0,G==1){for(y=0,h=h[0],N++;(_<it||y)&&N--;_++)X=y*f+(u[_]||0),x[_]=X/h|0,y=X%h|0;B=y||_<it}else{for(y=f/(h[0]+1)|0,y>1&&(h=n(h,y,f),u=n(u,y,f),G=h.length,it=u.length),tt=G,T=u.slice(0,G),C=T.length;C<G;)T[C++]=0;nt=h.slice(),nt.unshift(0),st=h[0],h[1]>=f/2&&++st;do y=0,c=i(h,T,G,C),c<0?(j=T[0],G!=C&&(j=j*f+(T[1]||0)),y=j/st|0,y>1?(y>=f&&(y=f-1),S=n(h,y,f),O=S.length,C=T.length,c=i(S,T,O,C),c==1&&(y--,t(S,G<O?nt:h,O,f))):(y==0&&(c=y=1),S=h.slice()),O=S.length,O<C&&S.unshift(0),t(T,S,C,f),c==-1&&(C=T.length,c=i(h,T,G,C),c<1&&(y++,t(T,G<C?nt:h,C,f))),C=T.length):c===0&&(y++,T=[0]),x[_++]=y,c&&T[0]?T[C++]=u[tt]||0:(T=[u[tt]],C=1);while((tt++<it||T[0]!==void 0)&&N--);B=T[0]!==void 0}x[0]||x.shift()}if(A==1)k.e=p,cr=B;else{for(_=1,y=x[0];y>=10;y/=10)_++;k.e=_+p*A-1,U(k,d?s+k.e+1:s,l,B)}return k}})();function U(n,i,t,r){var e,s,l,d,f,c,p,_,y,A=n.constructor;t:if(i!=null){if(_=n.d,!_)return n;for(e=1,d=_[0];d>=10;d/=10)e++;if(s=i-e,s<0)s+=Q,l=i,p=_[y=0],f=p/Ut(10,e-l-1)%10|0;else if(y=Math.ceil((s+1)/Q),d=_.length,y>=d)if(r){for(;d++<=y;)_.push(0);p=f=0,e=1,s%=Q,l=s-Q+1}else break t;else{for(p=d=_[y],e=1;d>=10;d/=10)e++;s%=Q,l=s-Q+e,f=l<0?0:p/Ut(10,e-l-1)%10|0}if(r=r||i<0||_[y+1]!==void 0||(l<0?p:p%Ut(10,e-l-1)),c=t<4?(f||r)&&(t==0||t==(n.s<0?3:2)):f>5||f==5&&(t==4||r||t==6&&(s>0?l>0?p/Ut(10,e-l):0:_[y-1])%10&1||t==(n.s<0?8:7)),i<1||!_[0])return _.length=0,c?(i-=n.e+1,_[0]=Ut(10,(Q-i%Q)%Q),n.e=-i||0):_[0]=n.e=0,n;if(s==0?(_.length=y,d=1,y--):(_.length=y+1,d=Ut(10,Q-s),_[y]=l>0?(p/Ut(10,e-l)%Ut(10,l)|0)*d:0),c)for(;;)if(y==0){for(s=1,l=_[0];l>=10;l/=10)s++;for(l=_[0]+=d,d=1;l>=10;l/=10)d++;s!=d&&(n.e++,_[0]==Xt&&(_[0]=1));break}else{if(_[y]+=d,_[y]!=Xt)break;_[y--]=0,d=1}for(s=_.length;_[--s]===0;)_.pop()}return $&&(n.e>A.maxE?(n.d=null,n.e=NaN):n.e<A.minE&&(n.e=0,n.d=[0])),n}function re(n,i,t){if(!n.isFinite())return vr(n);var r,e=n.e,s=Qt(n.d),l=s.length;return i?(t&&(r=t-l)>0?s=s.charAt(0)+"."+s.slice(1)+le(r):l>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(n.e<0?"e":"e+")+n.e):e<0?(s="0."+le(-e-1)+s,t&&(r=t-l)>0&&(s+=le(r))):e>=l?(s+=le(e+1-l),t&&(r=t-e-1)>0&&(s=s+"."+le(r))):((r=e+1)<l&&(s=s.slice(0,r)+"."+s.slice(r)),t&&(r=t-l)>0&&(e+1===l&&(s+="."),s+=le(r))),s}function je(n,i){var t=n[0];for(i*=Q;t>=10;t/=10)i++;return i}function Le(n,i,t){if(i>cn)throw $=!0,t&&(n.precision=t),Error(hr);return U(new n(Fe),i,1,!0)}function ie(n,i,t){if(i>Si)throw Error(hr);return U(new n(Ne),i,t,!0)}function gr(n){var i=n.length-1,t=i*Q+1;if(i=n[i],i){for(;i%10==0;i/=10)t--;for(i=n[0];i>=10;i/=10)t++}return t}function le(n){for(var i="";n--;)i+="0";return i}function br(n,i,t,r){var e,s=new n(1),l=Math.ceil(r/Q+4);for($=!1;;){if(t%2&&(s=s.times(i),dr(s.d,l)&&(e=!0)),t=Kt(t/2),t===0){t=s.d.length-1,e&&s.d[t]===0&&++s.d[t];break}i=i.times(i),dr(i.d,l)}return $=!0,s}function ur(n){return n.d[n.d.length-1]&1}function wr(n,i,t){for(var r,e,s=new n(i[0]),l=0;++l<i.length;){if(e=new n(i[l]),!e.s){s=e;break}r=s.cmp(e),(r===t||r===0&&s.s===t)&&(s=e)}return s}function Ii(n,i){var t,r,e,s,l,d,f,c=0,p=0,_=0,y=n.constructor,A=y.rounding,B=y.precision;if(!n.d||!n.d[0]||n.e>17)return new y(n.d?n.d[0]?n.s<0?0:1/0:1:n.s?n.s<0?0:n:NaN);for(i==null?($=!1,f=B):f=i,d=new y(.03125);n.e>-2;)n=n.times(d),_+=5;for(r=Math.log(Ut(2,_))/Math.LN10*2+5|0,f+=r,t=s=l=new y(1),y.precision=f;;){if(s=U(s.times(n),f,1),t=t.times(++p),d=l.plus(ot(s,t,f,1)),Qt(d.d).slice(0,f)===Qt(l.d).slice(0,f)){for(e=_;e--;)l=U(l.times(l),f,1);if(i==null)if(c<3&&Ie(l.d,f-r,A,c))y.precision=f+=10,t=s=d=new y(1),p=0,c++;else return U(l,y.precision=B,A,$=!0);else return y.precision=B,l}l=d}}function ue(n,i){var t,r,e,s,l,d,f,c,p,_,y,A=1,B=10,S=n,O=S.d,k=S.constructor,x=k.rounding,T=k.precision;if(S.s<0||!O||!O[0]||!S.e&&O[0]==1&&O.length==1)return new k(O&&!O[0]?-1/0:S.s!=1?NaN:O?0:S);if(i==null?($=!1,p=T):p=i,k.precision=p+=B,t=Qt(O),r=t.charAt(0),Math.abs(s=S.e)<15e14){for(;r<7&&r!=1||r==1&&t.charAt(1)>3;)S=S.times(n),t=Qt(S.d),r=t.charAt(0),A++;s=S.e,r>1?(S=new k("0."+t),s++):S=new k(r+"."+t.slice(1))}else return c=Le(k,p+2,T).times(s+""),S=ue(new k(r+"."+t.slice(1)),p-B).plus(c),k.precision=T,i==null?U(S,T,x,$=!0):S;for(_=S,f=l=S=ot(S.minus(1),S.plus(1),p,1),y=U(S.times(S),p,1),e=3;;){if(l=U(l.times(y),p,1),c=f.plus(ot(l,new k(e),p,1)),Qt(c.d).slice(0,p)===Qt(f.d).slice(0,p))if(f=f.times(2),s!==0&&(f=f.plus(Le(k,p+2,T).times(s+""))),f=ot(f,new k(A),p,1),i==null)if(Ie(f.d,p-B,x,d))k.precision=p+=B,c=l=S=ot(_.minus(1),_.plus(1),p,1),y=U(S.times(S),p,1),e=d=1;else return U(f,k.precision=T,x,$=!0);else return k.precision=T,f;f=c,e+=2}}function vr(n){return String(n.s*n.s/0)}function De(n,i){var t,r,e;for((t=i.indexOf("."))>-1&&(i=i.replace(".","")),(r=i.search(/e/i))>0?(t<0&&(t=r),t+=+i.slice(r+1),i=i.substring(0,r)):t<0&&(t=i.length),r=0;i.charCodeAt(r)===48;r++);for(e=i.length;i.charCodeAt(e-1)===48;--e);if(i=i.slice(r,e),i){if(e-=r,n.e=t=t-r-1,n.d=[],r=(t+1)%Q,t<0&&(r+=Q),r<e){for(r&&n.d.push(+i.slice(0,r)),e-=Q;r<e;)n.d.push(+i.slice(r,r+=Q));i=i.slice(r),r=Q-i.length}else r-=e;for(;r--;)i+="0";n.d.push(+i),$&&(n.e>n.constructor.maxE?(n.d=null,n.e=NaN):n.e<n.constructor.minE&&(n.e=0,n.d=[0]))}else n.e=0,n.d=[0];return n}function pn(n,i){var t,r,e,s,l,d,f,c,p;if(i.indexOf("_")>-1){if(i=i.replace(/(\d)_(?=\d)/g,"$1"),_r.test(i))return De(n,i)}else if(i==="Infinity"||i==="NaN")return+i||(n.s=NaN),n.e=NaN,n.d=null,n;if(un.test(i))t=16,i=i.toLowerCase();else if(ln.test(i))t=2;else if(dn.test(i))t=8;else throw Error(de+i);for(s=i.search(/p/i),s>0?(f=+i.slice(s+1),i=i.substring(2,s)):i=i.slice(2),s=i.indexOf("."),l=s>=0,r=n.constructor,l&&(i=i.replace(".",""),d=i.length,s=d-s,e=br(r,new r(t),s,s*2)),c=Re(i,t,Xt),p=c.length-1,s=p;c[s]===0;--s)c.pop();return s<0?new r(n.s*0):(n.e=je(c,p),n.d=c,$=!1,l&&(n=ot(n,e,d*4)),f&&(n=n.times(Math.abs(f)<54?Ut(2,f):Ee.pow(2,f))),$=!0,n)}function mn(n,i){var t,r=i.d.length;if(r<3)return i.isZero()?i:ve(n,2,i,i);t=1.4*Math.sqrt(r),t=t>16?16:t|0,i=i.times(1/We(5,t)),i=ve(n,2,i,i);for(var e,s=new n(5),l=new n(16),d=new n(20);t--;)e=i.times(i),i=i.times(s.plus(e.times(l.times(e).minus(d))));return i}function ve(n,i,t,r,e){var s,l,d,f,c=1,p=n.precision,_=Math.ceil(p/Q);for($=!1,f=t.times(t),d=new n(r);;){if(l=ot(d.times(f),new n(i++*i++),p,1),d=e?r.plus(l):r.minus(l),r=ot(l.times(f),new n(i++*i++),p,1),l=d.plus(r),l.d[_]!==void 0){for(s=_;l.d[s]===d.d[s]&&s--;);if(s==-1)break}s=d,d=r,r=l,l=s,c++}return $=!0,l.d.length=_+1,l}function We(n,i){for(var t=n;--i;)t*=n;return t}function yr(n,i){var t,r=i.s<0,e=ie(n,n.precision,1),s=e.times(.5);if(i=i.abs(),i.lte(s))return se=r?4:1,i;if(t=i.divToInt(e),t.isZero())se=r?3:2;else{if(i=i.minus(t.times(e)),i.lte(s))return se=ur(t)?r?2:3:r?4:1,i;se=ur(t)?r?1:4:r?3:2}return i.minus(e).abs()}function Ei(n,i,t,r){var e,s,l,d,f,c,p,_,y,A=n.constructor,B=t!==void 0;if(B?($t(t,1,fe),r===void 0?r=A.rounding:$t(r,0,8)):(t=A.precision,r=A.rounding),!n.isFinite())p=vr(n);else{for(p=re(n),l=p.indexOf("."),B?(e=2,i==16?t=t*4-3:i==8&&(t=t*3-2)):e=i,l>=0&&(p=p.replace(".",""),y=new A(1),y.e=p.length-l,y.d=Re(re(y),10,e),y.e=y.d.length),_=Re(p,10,e),s=f=_.length;_[--f]==0;)_.pop();if(!_[0])p=B?"0p+0":"0";else{if(l<0?s--:(n=new A(n),n.d=_,n.e=s,n=ot(n,y,t,r,0,e),_=n.d,s=n.e,c=cr),l=_[t],d=e/2,c=c||_[t+1]!==void 0,c=r<4?(l!==void 0||c)&&(r===0||r===(n.s<0?3:2)):l>d||l===d&&(r===4||c||r===6&&_[t-1]&1||r===(n.s<0?8:7)),_.length=t,c)for(;++_[--t]>e-1;)_[t]=0,t||(++s,_.unshift(1));for(f=_.length;!_[f-1];--f);for(l=0,p="";l<f;l++)p+=Ai.charAt(_[l]);if(B){if(f>1)if(i==16||i==8){for(l=i==16?4:3,--f;f%l;f++)p+="0";for(_=Re(p,e,i),f=_.length;!_[f-1];--f);for(l=1,p="1.";l<f;l++)p+=Ai.charAt(_[l])}else p=p.charAt(0)+"."+p.slice(1);p=p+(s<0?"p":"p+")+s}else if(s<0){for(;++s;)p="0"+p;p="0."+p}else if(++s>f)for(s-=f;s--;)p+="0";else s<f&&(p=p.slice(0,s)+"."+p.slice(s))}p=(i==16?"0x":i==2?"0b":i==8?"0o":"")+p}return n.s<0?"-"+p:p}function dr(n,i){if(n.length>i)return n.length=i,!0}function _n(n){return new this(n).abs()}function gn(n){return new this(n).acos()}function bn(n){return new this(n).acosh()}function wn(n,i){return new this(n).plus(i)}function vn(n){return new this(n).asin()}function yn(n){return new this(n).asinh()}function Mn(n){return new this(n).atan()}function Pn(n){return new this(n).atanh()}function An(n,i){n=new this(n),i=new this(i);var t,r=this.precision,e=this.rounding,s=r+4;return!n.s||!i.s?t=new this(NaN):!n.d&&!i.d?(t=ie(this,s,1).times(i.s>0?.25:.75),t.s=n.s):!i.d||n.isZero()?(t=i.s<0?ie(this,r,e):new this(0),t.s=n.s):!n.d||i.isZero()?(t=ie(this,s,1).times(.5),t.s=n.s):i.s<0?(this.precision=s,this.rounding=1,t=this.atan(ot(n,i,s,1)),i=ie(this,s,1),this.precision=r,this.rounding=e,t=n.s<0?t.minus(i):t.plus(i)):t=this.atan(ot(n,i,s,1)),t}function Bn(n){return new this(n).cbrt()}function Sn(n){return U(n=new this(n),n.e+1,2)}function In(n,i,t){return new this(n).clamp(i,t)}function En(n){if(!n||typeof n!="object")throw Error(qe+"Object expected");var i,t,r,e=n.defaults===!0,s=["precision",1,fe,"rounding",0,8,"toExpNeg",-we,0,"toExpPos",0,we,"maxE",0,we,"minE",-we,0,"modulo",0,9];for(i=0;i<s.length;i+=3)if(t=s[i],e&&(this[t]=Bi[t]),(r=n[t])!==void 0)if(Kt(r)===r&&r>=s[i+1]&&r<=s[i+2])this[t]=r;else throw Error(de+t+": "+r);if(t="crypto",e&&(this[t]=Bi[t]),(r=n[t])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[t]=!0;else throw Error(pr);else this[t]=!1;else throw Error(de+t+": "+r);return this}function On(n){return new this(n).cos()}function Tn(n){return new this(n).cosh()}function Mr(n){var i,t,r;function e(s){var l,d,f,c=this;if(!(c instanceof e))return new e(s);if(c.constructor=e,fr(s)){c.s=s.s,$?!s.d||s.e>e.maxE?(c.e=NaN,c.d=null):s.e<e.minE?(c.e=0,c.d=[0]):(c.e=s.e,c.d=s.d.slice()):(c.e=s.e,c.d=s.d?s.d.slice():s.d);return}if(f=typeof s,f==="number"){if(s===0){c.s=1/s<0?-1:1,c.e=0,c.d=[0];return}if(s<0?(s=-s,c.s=-1):c.s=1,s===~~s&&s<1e7){for(l=0,d=s;d>=10;d/=10)l++;$?l>e.maxE?(c.e=NaN,c.d=null):l<e.minE?(c.e=0,c.d=[0]):(c.e=l,c.d=[s]):(c.e=l,c.d=[s]);return}if(s*0!==0){s||(c.s=NaN),c.e=NaN,c.d=null;return}return De(c,s.toString())}if(f==="string")return(d=s.charCodeAt(0))===45?(s=s.slice(1),c.s=-1):(d===43&&(s=s.slice(1)),c.s=1),_r.test(s)?De(c,s):pn(c,s);if(f==="bigint")return s<0?(s=-s,c.s=-1):c.s=1,De(c,s.toString());throw Error(de+s)}if(e.prototype=I,e.ROUND_UP=0,e.ROUND_DOWN=1,e.ROUND_CEIL=2,e.ROUND_FLOOR=3,e.ROUND_HALF_UP=4,e.ROUND_HALF_DOWN=5,e.ROUND_HALF_EVEN=6,e.ROUND_HALF_CEIL=7,e.ROUND_HALF_FLOOR=8,e.EUCLID=9,e.config=e.set=En,e.clone=Mr,e.isDecimal=fr,e.abs=_n,e.acos=gn,e.acosh=bn,e.add=wn,e.asin=vn,e.asinh=yn,e.atan=Mn,e.atanh=Pn,e.atan2=An,e.cbrt=Bn,e.ceil=Sn,e.clamp=In,e.cos=On,e.cosh=Tn,e.div=Cn,e.exp=kn,e.floor=xn,e.hypot=Rn,e.ln=Dn,e.log=Fn,e.log10=Ln,e.log2=Nn,e.max=qn,e.min=jn,e.mod=Wn,e.mul=Zn,e.pow=Un,e.random=Hn,e.round=Qn,e.sign=Kn,e.sin=$n,e.sinh=zn,e.sqrt=Gn,e.sub=Vn,e.sum=Xn,e.tan=Jn,e.tanh=Yn,e.trunc=to,n===void 0&&(n={}),n&&n.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],i=0;i<r.length;)n.hasOwnProperty(t=r[i++])||(n[t]=this[t]);return e.config(n),e}function Cn(n,i){return new this(n).div(i)}function kn(n){return new this(n).exp()}function xn(n){return U(n=new this(n),n.e+1,3)}function Rn(){var n,i,t=new this(0);for($=!1,n=0;n<arguments.length;)if(i=new this(arguments[n++]),i.d)t.d&&(t=t.plus(i.times(i)));else{if(i.s)return $=!0,new this(1/0);t=i}return $=!0,t.sqrt()}function fr(n){return n instanceof Ee||n&&n.toStringTag===mr||!1}function Dn(n){return new this(n).ln()}function Fn(n,i){return new this(n).log(i)}function Nn(n){return new this(n).log(2)}function Ln(n){return new this(n).log(10)}function qn(){return wr(this,arguments,-1)}function jn(){return wr(this,arguments,1)}function Wn(n,i){return new this(n).mod(i)}function Zn(n,i){return new this(n).mul(i)}function Un(n,i){return new this(n).pow(i)}function Hn(n){var i,t,r,e,s=0,l=new this(1),d=[];if(n===void 0?n=this.precision:$t(n,1,fe),r=Math.ceil(n/Q),this.crypto)if(crypto.getRandomValues)for(i=crypto.getRandomValues(new Uint32Array(r));s<r;)e=i[s],e>=429e7?i[s]=crypto.getRandomValues(new Uint32Array(1))[0]:d[s++]=e%1e7;else if(crypto.randomBytes){for(i=crypto.randomBytes(r*=4);s<r;)e=i[s]+(i[s+1]<<8)+(i[s+2]<<16)+((i[s+3]&127)<<24),e>=214e7?crypto.randomBytes(4).copy(i,s):(d.push(e%1e7),s+=4);s=r/4}else throw Error(pr);else for(;s<r;)d[s++]=Math.random()*1e7|0;for(r=d[--s],n%=Q,r&&n&&(e=Ut(10,Q-n),d[s]=(r/e|0)*e);d[s]===0;s--)d.pop();if(s<0)t=0,d=[0];else{for(t=-1;d[0]===0;t-=Q)d.shift();for(r=1,e=d[0];e>=10;e/=10)r++;r<Q&&(t-=Q-r)}return l.e=t,l.d=d,l}function Qn(n){return U(n=new this(n),n.e+1,this.rounding)}function Kn(n){return n=new this(n),n.d?n.d[0]?n.s:0*n.s:n.s||NaN}function $n(n){return new this(n).sin()}function zn(n){return new this(n).sinh()}function Gn(n){return new this(n).sqrt()}function Vn(n,i){return new this(n).sub(i)}function Xn(){var n=0,i=arguments,t=new this(i[n]);for($=!1;t.s&&++n<i.length;)t=t.plus(i[n]);return $=!0,U(t,this.precision,this.rounding)}function Jn(n){return new this(n).tan()}function Yn(n){return new this(n).tanh()}function to(n){return U(n=new this(n),n.e+1,1)}I[Symbol.for("nodejs.util.inspect.custom")]=I.toString;I[Symbol.toStringTag]="Decimal";var Ee=I.constructor=Mr(Bi);Fe=new Ee(Fe);Ne=new Ee(Ne);var Z=Ee;var Ze=(r=>(r[r.Spot=0]="Spot",r[r.Curve=1]="Curve",r[r.BidAsk=2]="BidAsk",r))(Ze||{});import{d as K,DETAILS_KEYS as Ue,MathUtil as eo}from"@cetusprotocol/common-sdk";var ce=1e3,Co=-443636,ko=443636,he=1e4,Oe=2e3,ye=200,Me=443636n,Oi=1e8,Pr=1e9,Jt=1e4,xo=604800,Ro=1747627200;var rt=Mi(xe());var io=new rt.default(524288),q=64,Ti=new rt.default(1).shln(q),Ar=new rt.default(2).pow(new rt.default(128)).sub(new rt.default(1)),F=class n{static splitBinLiquidityInfo(i,t,r){let e=n.getPositionCount(t,r);if(e<=1)return[i];let s=[],l=t;for(let d=0;d<e;d++){let f=Math.min(l+1e3-2,r),c=i.bins.filter(p=>p.bin_id>=l&&p.bin_id<=f);s.push({bins:c,amount_a:c.reduce((p,_)=>K(p).plus(_.amount_a),K(0)).toFixed(0),amount_b:c.reduce((p,_)=>K(p).plus(_.amount_b),K(0)).toFixed(0)}),l=f+1}return s}static processBinsByRate(i,t){let r=[],e=K(0),s=K(0);return i.forEach(l=>{let{amount_a:d,amount_b:f,liquidity:c="0"}=l,p=K(t).mul(c).toFixed(0),_=K(d).mul(t),y=K(f).mul(t);K(_).lt(1)&&K(_).gt(0)&&(_=K(1)),K(y).lt(1)&&K(y).gt(0)&&(y=K(1)),e=K(e).plus(_),s=K(s).plus(y),r.push({bin_id:l.bin_id,amount_a:_.toFixed(0),amount_b:y.toFixed(0),price_per_lamport:l.price_per_lamport,liquidity:p})}),{bins:r,amount_a:e.toFixed(0),amount_b:s.toFixed(0)}}static calculateOutByShare(i,t){let{amount_a:r,amount_b:e,liquidity:s="0"}=i;if(s==="0")return{amount_a:"0",amount_b:"0"};if(K(t).gte(K(s)))return{amount_a:r,amount_b:e};let l=K(t).div(s).mul(r).toFixed(0,Z.ROUND_FLOOR),d=K(t).div(s).mul(e).toFixed(0,Z.ROUND_FLOOR);return{amount_a:l,amount_b:d}}static getPositionCount(i,t){let e=K(t).sub(i).add(1).div(1e3);return Number(e.toFixed(0,Z.ROUND_UP))}static getLiquidity(i,t,r){return K(r).mul(i).add(K(t).mul(K(2).pow(q))).toFixed(0)}static getAmountAFromLiquidity(i,t){return K(i).div(K(t)).toFixed(0)}static getAmountBFromLiquidity(i){return K(i).div(K(2).pow(q)).toFixed(0)}static getAmountsFromLiquidity(i,t,r,e){if(K(e).isZero()&&V("LiquiditySupplyIsZero","Liquidity supply is zero"),K(r).gt(K(e))&&V("InvalidDeltaLiquidity","Invalid delta liquidity"),K(r).isZero())return["0","0"];let s;K(i).isZero()?s="0":s=K(i).mul(K(r)).div(K(e)).toFixed(0,Z.ROUND_FLOOR);let l;return K(t).isZero()?l="0":l=K(t).mul(K(r)).div(K(e)).toFixed(0,Z.ROUND_FLOOR),[s,l]}static getPriceFromBinId(i,t,r,e){let s=n.getPricePerLamportFromBinId(i,t);return n.getPriceFromLamport(r,e,s).toString()}static getPricePerLamportFromBinId(i,t){let r=new Z(t).div(new Z(1e4));return new Z(1).add(new Z(r)).pow(new Z(i)).toString()}static getBinIdFromPrice(i,t,r,e,s){let l=n.getPricePerLamport(e,s,i);return n.getBinIdFromLamportPrice(l,t,r)}static getBinIdFromLamportPrice(i,t,r){let e=new Z(t).div(new Z(1e4)),s=new Z(i).log().dividedBy(new Z(1).add(e).log());return(r?s.floor():s.ceil()).toNumber()}static getPricePerLamport(i,t,r){return new Z(r).mul(new Z(10**(t-i))).toString()}static getPriceFromLamport(i,t,r){return new Z(r).div(new Z(10**(t-i))).toString()}static getReversePrice(i){return new Z(1).div(i).toString()}static getQPriceFromId(i,t){let r=new rt.default(t).shln(q).div(new rt.default(1e4)),e=Ti.add(r);return n.pow(e,new rt.default(i)).toString()}static getPricePerLamportFromQPrice(i){return eo.fromX64(new rt.default(i)).toString()}static pow(i,t){let r=t.isNeg();if(t.isZero())return Ti;if(t=r?t.abs():t,t.gt(io))return new rt.default(0);let e=i,s=Ti;return e.gte(s)&&(e=Ar.div(e),r=!r),t.and(new rt.default(1)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new rt.default(2)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new rt.default(4)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new rt.default(8)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new rt.default(16)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new rt.default(32)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new rt.default(64)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new rt.default(128)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new rt.default(256)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new rt.default(512)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new rt.default(1024)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new rt.default(2048)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new rt.default(4096)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new rt.default(8192)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new rt.default(16384)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new rt.default(32768)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new rt.default(65536)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new rt.default(131072)).isZero()||(s=s.mul(e).shrn(q)),e=e.mul(e).shrn(q),t.and(new rt.default(262144)).isZero()||(s=s.mul(e).shrn(q)),s.isZero()?new rt.default(0):(r&&(s=Ar.div(s)),s)}static binScore(i){let t=BigInt(i)+Me;return(t<0n||t>Me*2n)&&V("InvalidBinId",new Error("Invalid bin ID"),{[Ue.METHOD_NAME]:"binScore",[Ue.REQUEST_PARAMS]:{binId:i}}),t.toString()}static scoreToBinId(i){let t=BigInt(i)-Me;return(t<-Me||t>Me)&&V("InvalidBinId",new Error("Invalid score"),{[Ue.METHOD_NAME]:"scoreToBinId",[Ue.REQUEST_PARAMS]:{score:i}}),Number(t)}static resolveBinPosition(i){let t=BigInt(i),r=t>>4n,e=Number(t&0xfn);return[r.toString(),e]}static findMinMaxBinId(i){let t=1+i/1e4,e=new Z("18446744073709551615").log(10).div(new Z(t).log(10)).floor(),s=e.neg(),l=e,d=K(1),f=K("340282366920938463463374607431768211455");for(;;){let c=K(n.getQPriceFromId(s.toNumber(),i));if(c.gt(d)&&!c.isZero())break;s=s.add(1)}for(;;){let c=K(n.getQPriceFromId(l.toNumber(),i));if(c.lt(f)&&!c.isZero())break;l=l.sub(1)}return{minBinId:s.toNumber(),maxBinId:l.toNumber()}}static getBinShift(i,t,r){let e=n.getPricePerLamportFromBinId(i,t),s=K(e).mul(1+r).toString(),l=n.getBinIdFromLamportPrice(s,t,!0),d=K(l).sub(i).abs().toFixed(0,Z.ROUND_UP);return console.log("getBinShift Options:",{active_id:i,bin_shift:d}),Number(d)}};import{bcs as zt}from"@mysten/sui/bcs";import{blake2b as no}from"blakejs";function Ir(n){try{let i=n.parsedJson;return{id:i.pool_id,bin_step:Number(i.bin_step),coin_type_a:ne(i.coin_type_a,!1),coin_type_b:ne(i.coin_type_b,!1)}}catch(i){return V("ParseError",i,{[pe.METHOD_NAME]:"parseDlmmBasePool",[pe.REQUEST_PARAMS]:n})}}function He(n){try{let i=xi(n),t=Br(n),r=ki(t),e={bin_step:i.bin_manager.fields.bin_step,bin_manager_handle:i.bin_manager.fields.bins.fields.id.id,size:i.bin_manager.fields.bins.fields.size},s={bin_step:i.position_manager.fields.bin_step,position_index:i.position_manager.fields.position_index,position_handle:i.position_manager.fields.positions.fields.id.id,size:i.position_manager.fields.positions.fields.size},l=i.reward_manager.fields,d=l.rewards.map(_=>{let y=_.fields.current_emission_rate,A=ro.fromX64(new Sr.default(y)),B=Math.floor(A.toNumber()*60*60*24).toString();return{reward_coin:ne(_.fields.reward_coin.fields.name,!1),emissions_per_second:A.toString(),emissions_per_day:B,period_emission_rates:{id:_.fields.period_emission_rates.fields.id.id,size:_.fields.period_emission_rates.fields.size}}}),f={is_public:l.is_public,emergency_reward_pause:l.emergency_reward_pause,vault:{id:l.vault.fields.id.id,size:l.vault.fields.size},rewards:d,last_updated_time:l.last_updated_time},c={volatility_accumulator:i.v_parameters.fields.volatility_accumulator,volatility_reference:i.v_parameters.fields.volatility_reference,index_reference:Ae(BigInt(i.v_parameters.fields.index_reference.fields.bits)),last_update_timestamp:i.v_parameters.fields.last_update_timestamp,bin_step_config:i.v_parameters.fields.bin_step_config.fields},p={id:i.id.id,bin_step:Number(i.bin_step),coin_type_a:ne(r.type_arguments[0],!1),coin_type_b:ne(r.type_arguments[1],!1),pool_type:t,index:Number(i.index),bin_manager:e,variable_parameters:c,active_id:Ae(BigInt(i.active_id.fields.bits)),permissions:i.permissions.fields,balance_a:i.balance_a,balance_b:i.balance_b,base_fee_rate:i.base_fee_rate,protocol_fee_a:i.protocol_fee_a,protocol_fee_b:i.protocol_fee_b,url:i.url,reward_manager:f,position_manager:s};return p.bin_step=p.bin_manager.bin_step,p}catch(i){return console.log("\u{1F680} ~ parseDlmmPool ~ error:",i),V("ParseError",i,{[pe.METHOD_NAME]:"parseDlmmPool",[pe.REQUEST_PARAMS]:n})}}function Ri(n){let i=xi(n),t=Br(n),r=ki(t);return{id:i.id.id,name:i.name,ref_fee_rate:Ci(i.ref_fee_rate).div(1e4).toNumber(),start_time:Number(i.start_time),end_time:Number(i.end_time),balances:{id:i.balances.fields.id.id,size:i.balances.fields.size},type:r.full_address}}function Di(n){try{let i=xi(n);return{uri:i.uri,index:i.index,id:i.id.id,name:i.name,pool_id:i.pool_id,lower_bin_id:Ae(BigInt(i.lower_bin_id.fields.bits)),upper_bin_id:Ae(BigInt(i.upper_bin_id.fields.bits)),liquidity_shares:i.liquidity_shares,description:i.description,coin_type_a:ne(i.coin_type_a,!1),coin_type_b:ne(i.coin_type_b,!1)}}catch(i){return console.log("\u{1F680} ~ parseDlmmPosition ~ error:",i),V("ParseError",i,{[pe.METHOD_NAME]:"parseDlmmPosition",[pe.REQUEST_PARAMS]:n})}}function ms(n,i,t,r){let e=n.map((d,f)=>{let c=t+f,p=F.getPricePerLamportFromBinId(c,i);if(c===r.bin_id){let{amount_a:A,amount_b:B}=F.calculateOutByShare(r,d);return{bin_id:c,amount_a:A,amount_b:B,liquidity:d,price_per_lamport:p}}if(c<r.bin_id){let A=F.getAmountBFromLiquidity(d);return{bin_id:c,amount_a:"0",amount_b:A,liquidity:d,price_per_lamport:p}}let _=F.getQPriceFromId(c,i),y=F.getAmountAFromLiquidity(d,_);return{bin_id:c,amount_a:y,amount_b:"0",liquidity:d,price_per_lamport:p}}),s=e.reduce((d,f)=>d.add(new Z(f.amount_a)),new Z(0)).toFixed(0),l=e.reduce((d,f)=>d.add(new Z(f.amount_b)),new Z(0)).toFixed(0);return{bins:e,amount_a:s,amount_b:l}}function Er(n){try{let i=zt.struct("BinAmount",{id:zt.struct("I32",{bits:zt.u32()}),amount_a:zt.u64(),amount_b:zt.u64(),price:zt.u128(),liquidity_supply:zt.u128(),rewards_growth_global:zt.vector(zt.u128()),fee_a_growth_global:zt.u128(),fee_b_growth_global:zt.u128()});return zt.vector(i).parse(Uint8Array.from(n.results[1].returnValues[0][0])).map(r=>({bin_id:Ae(BigInt(r.id.bits)),amount_a:r.amount_a,amount_b:r.amount_b,liquidity:r.liquidity_supply,price_per_lamport:F.getPricePerLamportFromQPrice(r.price)}))}catch(i){return console.log("\u{1F680} ~ parseBinInfo ~ error:",i),[]}}function Fi(n){try{return{bin_id:Ae(BigInt(n.id.fields.bits)),amount_a:n.amount_a,amount_b:n.amount_b,liquidity:n.liquidity_share,price_per_lamport:F.getPricePerLamportFromQPrice(n.price)}}catch(i){return V("ParseError",i,{[pe.METHOD_NAME]:"parseBinInfo",[pe.REQUEST_PARAMS]:{fields:n}})}}function Or(n){let i={},t=n.events?.filter(r=>r.type.includes("pool::CollectFeeEvent"));for(let r=0;r<t.length;r+=1){let{parsedJson:e}=t[r],s={position_id:e.position,fee_owned_a:e.fee_a,fee_owned_b:e.fee_b};i[e.position]=s}return i}function Tr(n){let i={},t=n.events?.filter(r=>r.type.includes("pool::CollectRewardEvent"));for(let r=0;r<t.length;r+=1){let{parsedJson:e}=t[r],s=e.position,l=e.reward,d=e.amount,f={coin_type:ne(l.name,!1),reward_owned:d},c=i[s];c?c.rewards.push(f):c={position_id:s,rewards:[f]},i[s]=c}return i}function Cr(n,i){let t=n.events?.filter(r=>r.type.includes("pool::SwapEvent"));for(let r=0;r<t.length;r+=1){let{parsedJson:e}=t[r],{partner:s,pool:l,amount_in:d,amount_out:f,fee:c,ref_fee:p,bin_swaps:_,from:y,target:A}=e,B=_.map(O=>({bin_id:O.bin_id.bits,in_amount:O.amount_in,out_amount:O.amount_out,fee:O.fee,var_fee_rate:O.var_fee_rate}));return{pool_id:l,a2b:i,in_amount:d,out_amount:f,ref_fee_amount:p,fee_amount:c,bin_swaps:B,partner:s,from_coin_type:ne(y.name,!1),to_coin_type:ne(A.name,!1)}}}function _s(n){switch(n){case 0:return 0;case 1:return 1;case 2:return 2}}var oo=["RemoveLiquidityEvent","SwapEvent","AddLiquidityEvent","ClosePositionEvent"];function kr(n,i,t,r){let e=[],{timestampMs:s,events:l}=n;return l?.forEach((d,f)=>{let{name:c,address:p}=ki(d.type);if(oo.includes(c)&&p===t&&r===d.parsedJson.pool){let _={tx:d.id.txDigest,sender:d.sender,type:d.type,block_time:s||"0",index:`${i}_${f}`,parsed_json:d.parsedJson};e.push(_)}}),e}function gs(n,i,t){let r=[],e=0,s=new Date(n*1e3).getTime(),l=new Date().getTime();for(;;){let d=s+e*t;if(d>=l&&r.push(d),e>=i)break;e+=1}return r}function bs(n,i,t,r){let e=[];for(let s=i;s<=t;s+=r){let l=n.findLast(d=>Ci(s).gte(d.time));l?e.push({time:s.toString(),emissions_per_second:l.emissions_per_second,emissions_per_day:l.emissions_per_day,visualized_time:new Date(s*1e3).toLocaleString()}):e.push({emissions_per_day:"0",time:s.toString(),emissions_per_second:"0",visualized_time:new Date(s*1e3).toLocaleString()})}return e}function ws(n){if(n.length===0)return;let i=new Date().getTime()/1e3,t=n.findLast(r=>Ci(i).gte(r.time));return t||n[n.length-1]}function oe(n,i){let t=n.mul(i);if(t.gt(0)&&t.lt(1))throw new ge(`Multiplication ${t} is less than 1`,"AmountTooSmall");return t.floor()}function Te(n){if(n.gt(0)&&n.lt(1))throw new ge(`Multiplication ${n.toString()} is less than 1`,"AmountTooSmall");return n.floor()}function xr(n){switch(n){case 0:return"spot";case 1:return"curve";case 2:return"bid_ask"}}function Rr(n,i,t,r){let e=Buffer.from(n,"utf8"),s=Buffer.from(i,"utf8"),l=s.length,d=0;for(;d<l;){let y=s[d];e=Buffer.concat([e,Buffer.from([y])]),d++}let f=zt.u16().serialize(t).toBytes(),c=zt.u16().serialize(r).toBytes(),p=Buffer.concat([e,f,c]),_=no(p,void 0,32);return`0x${Buffer.from(_).toString("hex")}`}import{d as E}from"@cetusprotocol/common-sdk";var Yt=class n{static toWeight(i){console.log("\u{1F680} ~ WeightUtils ~ toWeight ~ options:",i);let{strategy_type:t,active_id:r,bin_step:e,lower_bin_id:s,upper_bin_id:l,total_amount_a:d,total_amount_b:f,active_bin_of_pool:c}=i,p=r<s||r>l,_=F.getQPriceFromId(r,e),y=E(0),A=E(0),B=E(200);if(t===2?B=E(200):t===1?B=E(2e3):t===0&&(B=E(1)),!p&&c){let it=this.calculateActiveWeights(c.amount_a,c.amount_b,_,B);y=it.active_weight_a,A=it.active_weight_b}r===s&&E(f).isZero()&&(y=E(B).mul(E(2).pow(q*2)).div(E(_)).floor(),A=E(0)),r===l&&E(d).isZero()&&(A=E(B).mul(E(2).pow(q)).floor(),y=E(0)),r>s&&r<l&&(E(d).isZero()&&(A=E(B).mul(E(2).pow(q)).floor(),y=E(0)),E(f).isZero()&&(y=E(B).mul(E(2).pow(q*2)).div(E(_)).floor(),A=E(0)));let S=p?E(0):y,O=p?E(0):A,k=E(2e3).sub(E(200)).floor(),x=r>l?l:r,T=r<s?s:r,C=r>s?x===s?E(0):k.div(E(x-s)).floor():E(0),j=l>r?T===l?E(0):k.div(E(l-T)).floor():E(0),N=s,X=[],tt=[];for(;N<=l;){let it=E(0);if(N<r){let st=x-N;t===0?it=E(1):t===2?it=E(B).add(C.mul(st)).floor():t===1&&(it=E(B).sub(C.mul(st)).floor())}else if(N>r){let st=N-T;t===0?it=E(1):t===2?it=E(B).add(j.mul(st)).floor():t===1&&(it=E(B).sub(j.mul(st)).floor())}else it=B;if(X.push(it),N<r)O=O.add(it.mul(E(2).pow(q))).floor(),tt.push(E(0));else if(N>r){let st=it.mul(E(2).pow(q*2)).div(F.getQPriceFromId(N,e)).floor();tt.push(st),S=S.add(st).floor()}else tt.push(E(0));N+=1}return{...i,total_weight_a:S,total_weight_b:O,active_weight_a:y,active_weight_b:A,weights:X,weight_per_prices:tt}}static toWeightSpotBalanced(i,t){let r=[];for(let e=i;e<=t;e++)r.push({bin_id:e,weight:1});return r}static toWeightDescendingOrder(i,t){let r=[];for(let e=i;e<=t;e++)r.push({bin_id:e,weight:t-e+1});return r}static toWeightAscendingOrder(i,t){let r=[];for(let e=i;e<=t;e++)r.push({bin_id:e,weight:e-i+1});return r}static toWeightCurve(i,t,r){if(r<i)return n.toWeightDescendingOrder(i,t);if(r>t)return n.toWeightAscendingOrder(i,t);let e=2e3,l=e-200,d=r>i?Math.floor(l/(r-i)):0,f=t>r?Math.floor(l/(t-r)):0,c=[];for(let p=i;p<=t;p++)p<r?c.push({bin_id:p,weight:e-(r-p)*d}):p>r?c.push({bin_id:p,weight:e-(p-r)*f}):c.push({bin_id:p,weight:e});return c}static toWeightBidAsk(i,t,r){if(r>t)return n.toWeightDescendingOrder(i,t);if(r<i)return n.toWeightAscendingOrder(i,t);let e=2e3,s=200,l=e-s,d=r>i?Math.floor(l/(r-i)):0,f=t>r?Math.floor(l/(t-r)):0,c=[];for(let p=i;p<=t;p++)p<r?c.push({bin_id:p,weight:s+(r-p)*d}):p>r?c.push({bin_id:p,weight:s+(p-r)*f}):c.push({bin_id:p,weight:s});return c}static toAmountBidSide(i,t,r,e,s=!1){let l=e.filter(f=>f.bin_id<=i).reduce(function(f,c){return s?c.bin_id>i?f:f.add(c.weight):c.bin_id>=i?f:f.add(c.weight)},E(0));if(l.cmp(E(0))!=1)throw Error("Invalid parameters");return{bins:e.map(f=>{let c=F.getPricePerLamportFromBinId(f.bin_id,r);if(!(f.bin_id<=i)||f.bin_id>=i&&!s)return{bin_id:f.bin_id,amount_a:"0",amount_b:"0",price_per_lamport:c,liquidity:"0"};{let _=E(f.weight).div(l),y=oe(E(t),_).toString(),A="0",B=F.getQPriceFromId(f.bin_id,r),S=F.getLiquidity(A,y,B);return{bin_id:f.bin_id,amount_b:y,amount_a:A,price_per_lamport:c,liquidity:S}}}),amount_a:"0",amount_b:t}}static toAmountAskSide(i,t,r,e,s=!1){let l=e.filter(f=>f.bin_id>=i).reduce(function(f,c){if(c.bin_id<=i&&!s)return f;{let p=F.getPricePerLamportFromBinId(c.bin_id,t),_=new Z(c.weight).div(p);return f.add(_)}},new Z(0));if(l.cmp(new Z(0))!=1)throw Error("Invalid parameters");return{bins:e.map(f=>{let c=F.getPricePerLamportFromBinId(f.bin_id,t);if(!(f.bin_id>=i)||f.bin_id<=i&&!s)return{bin_id:f.bin_id,amount_a:"0",amount_b:"0",price_per_lamport:c,liquidity:"0"};{let y=new Z(f.weight).div(c).div(l),A=oe(E(r),y).toString(),B="0",S=F.getQPriceFromId(f.bin_id,t),O=F.getLiquidity(A,B,S);return{bin_id:f.bin_id,amount_a:A,amount_b:B,price_per_lamport:c,liquidity:O}}}),amount_a:r,amount_b:"0"}}static toAmountBothSide(i,t,r,e,s,l,d){let f=!E(r).isZero()&&E(e).isZero(),c=E(r).isZero()&&!E(e).isZero();if(i>d[d.length-1].bin_id)return n.toAmountBidSide(i,e,t,d);if(c&&i!==d[d.length-1].bin_id)return n.toAmountBidSide(i,e,t,d,!0);if(i<d[0].bin_id)return n.toAmountAskSide(i,t,r,d);if(f&&i!==d[0].bin_id)return n.toAmountAskSide(i,t,r,d,!0);let p=d.filter(_=>_.bin_id===i);if(p.length===1){let{totalWeightA:_,totalWeightB:y,activeWeightA:A,activeWeightB:B}=n.calculateTotalWeights(t,d,i,p[0],s,l,f?"a":c?"b":void 0),S=new Z(r.toString()).div(_),O=new Z(e.toString()).div(y),k=d.map(C=>{let j=F.getPricePerLamportFromBinId(C.bin_id,t);if(C.bin_id<i||C.bin_id===i&&c){let nt=oe(O,new Z(C.weight)),v="0",o=F.getQPriceFromId(C.bin_id,t),u=F.getLiquidity(v,nt.toString(),o);return{bin_id:C.bin_id,amount_a:"0",amount_b:nt.toString(),price_per_lamport:j,liquidity:u}}if(C.bin_id>i||C.bin_id===i&&f){let nt=new Z(C.weight).div(j),v=oe(S,new Z(nt)),o="0",u=F.getQPriceFromId(C.bin_id,t),h=F.getLiquidity(v.toString(),o,u);return{bin_id:C.bin_id,amount_a:v.toString(),amount_b:"0",price_per_lamport:j,liquidity:h}}let N=oe(S,A),X=oe(O,B),tt=N.toString(),it=X.toString(),st=F.getQPriceFromId(C.bin_id,t),G=F.getLiquidity(tt,it,st);return{bin_id:C.bin_id,amount_a:tt,amount_b:it,price_per_lamport:j,liquidity:G}}),x=k.reduce((C,j)=>E(C).add(E(j.amount_a)),E(0)).toString(),T=k.reduce((C,j)=>E(C).add(E(j.amount_b)),E(0)).toString();return{bins:k,amount_a:x,amount_b:T}}else{let{totalWeightA:_,totalWeightB:y}=n.calculateTotalWeights(t,d,i),A=new Z(r.toString()).div(_),B=new Z(e.toString()).div(y),S=d.map(x=>{let T=F.getPricePerLamportFromBinId(x.bin_id,t);if(x.bin_id<i){let C=oe(B,new Z(x.weight));return{bin_id:x.bin_id,amount_a:"0",amount_b:C.toString(),price_per_lamport:T}}else{let C=new Z(x.weight).div(T),j=oe(A,C);return{bin_id:x.bin_id,amount_a:j.toString(),amount_b:"0",price_per_lamport:T}}}),O=S.reduce((x,T)=>E(x).add(E(T.amount_a)),E(0)).toString(),k=S.reduce((x,T)=>E(x).add(E(T.amount_b)),E(0)).toString();return{bins:S,amount_a:O,amount_b:k}}}static autoFillCoinByWeight(i,t,r,e,s,l,d){if(i>d[d.length-1].bin_id)return n.toAmountBidSide(i,r,t,d);if(i<d[0].bin_id)return n.toAmountAskSide(i,t,r,d);let f=d.filter(A=>A.bin_id===i),{totalWeightA:c,totalWeightB:p}=n.calculateTotalWeights(t,d,i,f.length===1?f[0]:void 0,f.length===1?s:void 0,f.length===1?l:void 0),_=E(0);e?_=c.isZero()?new Z(0):new Z(r).div(c):_=p.isZero()?new Z(0):new Z(r).div(p);let y=oe(_,e?p:c).toString();return n.toAmountBothSide(i,t,e?r:y,e?y:r,s,l,d)}static calculateActiveWeights(i,t,r,e){let s=E(r),l=E(i),d=E(t),f=E(0),c=E(0);if(l.isZero()&&d.isZero())f=E(e).mul(E(2).pow(q*2)).div(s.mul(2)).floor(),c=E(e).mul(E(2).pow(q)).div(2).floor();else{if(l.isZero())f=E(0);else{let p=d.mul(E(2).pow(q)).div(l);f=E(e).mul(E(2).pow(q*2)).div(s.add(p)).floor()}if(d.isZero())c=E(0);else{let p=E(2).pow(q).add(s.mul(l).div(d)).floor();c=E(e).mul(E(2).pow(q*2)).div(p).floor()}}return{active_weight_a:f,active_weight_b:c}}static calculateTotalWeights(i,t,r,e,s,l,d){let f=E(F.getPricePerLamportFromBinId(r,i)),c=E(0),p=E(0);if(s&&l&&e&&!d)if(E(s).isZero()&&E(l).isZero())c=new Z(e.weight).div(f.mul(new Z(2))),p=new Z(e.weight).div(new Z(2));else{let A=new Z(s.toString()),B=new Z(l.toString());E(s).isZero()||(c=new Z(e.weight).div(f.add(B.div(A)))),E(l).isZero()||(p=new Z(e.weight).div(new Z(1).add(f.mul(A).div(B))))}let _=c,y=p;return t.forEach(A=>{if((A.bin_id<r||d==="b")&&(y=y.add(new Z(A.weight))),A.bin_id>r||d==="a"){let B=F.getPricePerLamportFromBinId(A.bin_id,i),S=new Z(A.weight).div(B);_=_.add(S)}}),{totalWeightA:_,totalWeightB:y,activeWeightA:c,activeWeightB:p}}};import{d as Gt}from"@cetusprotocol/common-sdk";var Ce=class{static toAmountsByWeights(i){let{total_weight_a:t,total_weight_b:r,weights:e,weight_per_prices:s,total_amount_a:l,total_amount_b:d,active_weight_a:f,active_weight_b:c,lower_bin_id:p,upper_bin_id:_,active_id:y,bin_step:A}=i,B=r.isZero()?Gt(0):Gt(d).mul(Gt(2).pow(q*2)).div(r).floor(),S=t.isZero()?Gt(0):Gt(l).mul(Gt(2).pow(q*2)).div(t).floor(),O=Te(S.mul(f).div(Gt(2).pow(q*2))),k=Te(B.mul(c).div(Gt(2).pow(q*2))),x=_-p+1,T=p,C=0,j=[];for(;C<x;){let X=Gt(0),tt=Gt(0),it=F.getQPriceFromId(T,A);T<y?tt=Te(B.mul(e[C]).div(Gt(2).pow(q))):T>y?X=Te(S.mul(s[C]).div(Gt(2).pow(q*2))):(X=O,tt=k);let st=F.getLiquidity(X.toString(),tt.toString(),it);j.push({bin_id:T,amount_a:X.toString(),amount_b:tt.toString(),price_per_lamport:F.getPricePerLamportFromBinId(T,A),liquidity:st}),T+=1,C+=1}return{bins:j,amount_a:l.toString(),amount_b:d.toString()}}static toAmountsBothSideByStrategy(i,t,r,e,s,l,d,f){let c=Yt.toWeight({strategy_type:d,active_id:i,bin_step:t,lower_bin_id:r,upper_bin_id:e,total_amount_a:s,total_amount_b:l,active_bin_of_pool:f});return this.toAmountsByWeights(c)}static autoFillCoinByStrategy(i,t,r,e,s,l,d,f){switch(d){case 0:{let c=Yt.toWeightSpotBalanced(s,l);return Yt.autoFillCoinByWeight(i,t,r,e,f?.amount_a||"0",f?.amount_b||"0",c)}case 1:{let c=Yt.toWeightCurve(s,l,i);return Yt.autoFillCoinByWeight(i,t,r,e,f?.amount_a||"0",f?.amount_b||"0",c)}case 2:{let c=Yt.toWeightBidAsk(s,l,i);return Yt.autoFillCoinByWeight(i,t,r,e,f?.amount_a||"0",f?.amount_b||"0",c)}}}static autoFillCoinByStrategyV2(i,t,r,e,s,l,d,f){let c=this.autoFillCoinByStrategy(i,t,r,e,s,l,d,f),p=Yt.toWeight({strategy_type:d,active_id:i,bin_step:t,lower_bin_id:s,upper_bin_id:l,total_amount_a:c.amount_a,total_amount_b:c.amount_b,active_bin_of_pool:f});return this.toAmountsByWeights(p)}};import{d as at}from"@cetusprotocol/common-sdk";var Qe=class n{static getVariableFee(i){let{volatility_accumulator:t,bin_step_config:r}=i,{variable_fee_control:e,bin_step:s}=r;return at(e).gt(0)?at(t).mul(s).pow(2).mul(e).add(99999999999).div(1e11).toFixed(0):"0"}static calculateCompositionFee(i,t){let r=at(i).mul(t);return at(r).mul(at(1e9).add(t)).div(1e18).toFixed(0)}static calculateProtocolFee(i,t){return at(i).mul(t).div(1e4).ceil().toFixed(0)}static getProtocolFees(i,t,r){let e=n.calculateProtocolFee(i,r),s=n.calculateProtocolFee(t,r);return{protocol_fee_a:e,protocol_fee_b:s}}static getCompositionFees(i,t,r){let{bin_step_config:e}=r;if(at(i.liquidity||"0").eq(at(0)))return{fees_a:"0",fees_b:"0"};let{bin_step:s,base_factor:l}=e,d=F.getQPriceFromId(i.bin_id,s),f=F.getLiquidity(i.amount_a,i.amount_b,d),c=F.getLiquidity(t.amount_a,t.amount_b,d),p=at(i.liquidity).mul(c).div(f).toFixed(0),{amount_a:_,amount_b:y}=F.calculateOutByShare({bin_id:i.bin_id,liquidity:at(i.liquidity).add(p).toFixed(0),amount_a:at(i.amount_a).add(t.amount_a).toFixed(0),amount_b:at(i.amount_b).add(t.amount_b).toFixed(0),price_per_lamport:i.price_per_lamport},p),A=at(s).mul(l).mul(10),B=n.getVariableFee(r),S=at(A).add(B).toFixed(0);at(S).gt(1e8)&&(S=1e8.toString());let O="0",k="0";return at(_).gt(t.amount_a)&&at(t.amount_b).gt(y)?k=n.calculateCompositionFee(at(t.amount_b).sub(y).toFixed(0),S):at(y).gt(t.amount_b)&&at(t.amount_a).gt(_)&&(O=n.calculateCompositionFee(at(t.amount_a).sub(_).toFixed(0),S)),{fees_a:O,fees_b:k}}};var Dr=class{static calculateIlm(i){let{curvature:t,initial_price:r,max_price:e,bin_step:s,total_supply:l,pool_share_percentage:d,config:f}=i,{price_curve_points_num:c,liquidity_distribution_num:p,tokens_table_num:_,price_table_num:y}=f;if(d<0||d>100)throw new Error("Pool Share Percentage must be greater than 0 and less than 100.");let A=!1;if(e<r)throw new Error("Maximum Price must be greater or equal to Initial Price.");if(e===r&&t!==0)throw new Error("Curvature must be 0 when Maximum and Initial Price are equal.");if(e!==r&&t===0)throw new Error("Maximum and Initial Price must be equal when Curvature is 0.");e===r&&t===0&&(A=!0);let B=L=>N*Math.pow(L/j,t)+r,S=(L,et)=>{let H=N*Math.pow(j,-t)*Math.pow(L,t+1)/(t+1)+r*L,Y=N*Math.pow(j,-t)*Math.pow(et,t+1)/(t+1)+r*et;return H-Y},O=L=>j*Math.pow((L-r)/N,1/t),k=L=>j*Math.pow(L-r,1/t-1)/(t*Math.pow(N,1/t)),x=L=>Math.pow((L-r)/N,1/t)*j,T=(L,et,H)=>{let Y=et/1e4,Se=Math.log(L)/Math.log(1+Y);return H?Math.floor(Se):Math.ceil(Se)},C=(L,et)=>{let H=et/1e4;return Math.pow(1+H,L)},j=l*d/100,N=e-r,X=[],tt=[],it=T(r,s,!1),st=T(e,s,!1),G=0,nt=it;if(A)X.push(r),tt.push(r*j);else for(;nt<=st;){let L=C(nt,s),et=C(nt+1,s),H=x(et)-x(L);G=G+H,tt.push(H*L),X.push(L),nt++}let v={price_curve:{data:[],min_y:0,max_y:0},liquidity_curve:{data:[],min_y:0,max_y:0},dlmm_bins:{data:[],min_y:0,max_y:0},tokens_table:[],price_table:[],initial_fdv:r*l,final_fdv:e*l,usdc_in_pool:0};var o=N/100;let u=[],h=0,m=0;for(let L=0;L<c;L++){let et=L*j/(c-1),H=A?e:B(et);h=h<H?h:H,m=m>H?m:H,u.push({x:et,y:H})}v.price_curve={data:u,min_y:h,max_y:m};let b=[],M=0,P=0;if(A)M=0,P=j,b=[{x:r,y:0},{x:r,y:j/2},{x:r,y:j}];else for(let L=0;L<p;L++){let et=r+L*o,H=k(et);b.push({x:et,y:H}),M=M<H?M:H,P=P>H?P:H}v.liquidity_curve={data:b,min_y:M,max_y:P};let g=[],a=0,w=0;X.forEach((L,et)=>{let H=L,Y=tt[et];g.push({x:H,y:Y}),a=a<Y?a:Y,w=w>Y?w:Y}),v.dlmm_bins={data:g,min_y:a,max_y:w};let R=[],D=0,W=j/_;for(;D<=j;){let L=B(D),et=D,H=S(et,0);R.push({withdrawn:et,price:L,usdc_in_pool:H}),D=D+W}v.tokens_table=R;let z=Math.floor(N*1e10)/1e11,J=[];if(A)J.push({withdrawn:j,price:r,usdc_in_pool:j*r});else{let L=0,et=r;for(;L<=y;){let H=O(et),Y=S(H,0);J.push({withdrawn:H,price:et,usdc_in_pool:Y}),et=et+z,L=L+1}}return v.price_table=J,v.usdc_in_pool=J[J.length-1].usdc_in_pool,v}};import{SuiClient as fo}from"@mysten/sui/client";import{normalizeSuiAddress as jr}from"@mysten/sui/utils";import{bcs as $e}from"@mysten/sui/bcs";var ze=class{constructor(i){this._sdk=i}get sdk(){return this._sdk}async getPoolAddress(i,t,r,e){try{let s=Rr(i,t,r,e),{dlmm_pool:l}=this._sdk.sdkOptions,{pools_id:d}=qr(l),f=await this._sdk.FullClient.getDynamicFieldObject({parentId:d,name:{type:"0x2::object::ID",value:s}});return Lr(f).value.fields.value.fields.pool_id}catch(s){return V("FetchError",s,{[te.METHOD_NAME]:"getPoolAddress",[te.REQUEST_PARAMS]:{coin_type_a:i,coin_type_b:t,bin_step:r,base_factor:e}})}}async getBasePoolList(i="all",t=!1){let{dlmm_pool:r}=this._sdk.sdkOptions,e={data:[],has_next_page:!1},s=i==="all",l=`${r.package_id}_getBasePoolList`;if(s){let d=this._sdk.getCache(l,t);if(d&&d.length>0)return e.data.push(...d),e}try{let d=`${r.package_id}::registry::CreatePoolEvent`,f=await this._sdk.FullClient.queryEventsByPage({MoveEventType:d},i);e.has_next_page=f.has_next_page,e.next_cursor=f.next_cursor,f.data.forEach(c=>{let p=Ir(c);e.data.push(p)}),s&&this._sdk.updateCache(`${r.package_id}_getPoolImmutables`,e.data)}catch(d){return V("FetchError",d,{[te.METHOD_NAME]:"getBasePoolList"})}return e}async getPools(i="all",t=!1){let r={data:[],has_next_page:!1},e=await this.getBasePoolList(i,t);if(e.data.length===0)return r;try{let s=await this._sdk.FullClient.batchGetObjects(e.data.map(l=>l.id),{showContent:!0,showType:!0});r.has_next_page=e.has_next_page,r.next_cursor=e.next_cursor;for(let l of s){let d=He(l),f=`${d.id}_getDlmmPool`;this._sdk.updateCache(f,d),r.data.push(d)}}catch(s){return V("FetchError",s,{[te.METHOD_NAME]:"getPools"})}return r}async getBinInfo(i,t,r,e=!0){try{let s=`${i}_getBinInfo_${t}`,l=this._sdk.getCache(s,e);if(l!==void 0)return l;let d=F.binScore(t),[f,c]=F.resolveBinPosition(d),_=(await this._sdk.FullClient.getDynamicFieldObject({parentId:i,name:{type:"u64",value:f}})).data.content.fields.value.fields.value.fields.group.fields.bins[c].fields,y=Fi(_);return this._sdk.updateCache(s,y),y}catch{return{bin_id:t,amount_a:"0",amount_b:"0",liquidity:"0",price_per_lamport:F.getPricePerLamportFromBinId(t,r)}}}async getBinInfoList(i){let t=[],r=i.map(s=>{let{bin_manager_handle:l,bin_id:d,bin_step:f}=s,c=F.binScore(d),[p,_]=F.resolveBinPosition(c),y=lo(l,p,"u64","u64");return{groupIndex:p,offsetInGroup:_,bin_id:d,bin_step:f,bin_manager_handle:l,dynamic_field_id:y}});return(await this._sdk.FullClient.batchGetObjects(r.map(s=>s.dynamic_field_id),{showContent:!0,showType:!0})).forEach((s,l)=>{let{offsetInGroup:d,bin_manager_handle:f,bin_step:c,bin_id:p}=r[l];try{let y=Lr(s).value.fields.value.fields.group.fields.bins[d].fields,A=Fi(y);t.push({...A,bin_manager_handle:f,bin_step:c})}catch{t.push({bin_id:p,amount_a:"0",amount_b:"0",liquidity:"0",price_per_lamport:F.getPricePerLamportFromBinId(p,c),bin_manager_handle:f,bin_step:c})}}),t}async getTotalFeeRate(i){let{dlmm_pool:t}=this._sdk.sdkOptions,{pool_id:r,coin_type_a:e,coin_type_b:s}=i,l=new Ke;l.moveCall({target:`${t.published_at}::pool::get_total_fee_rate`,arguments:[l.object(r)],typeArguments:[e,s]});let d=await this._sdk.FullClient.devInspectTransactionBlock({transactionBlock:l,sender:jr("0x0")});return $e.struct("FeeRate",{base_fee_rate:$e.u64(),var_fee_rate:$e.u64(),total_fee_rate:$e.u64()}).parse(Uint8Array.from(d.results[0].returnValues[0][0]))}async getPoolBinInfo(i){let{dlmm_pool:t}=this._sdk.sdkOptions,{pool_id:r,coin_type_a:e,coin_type_b:s}=i,l=1e3,d=[],f,c=!0;for(;c;){let p=new Ke,_;f!==void 0?_=p.moveCall({target:"0x1::option::some",arguments:[p.pure.u32(Number(Fr(BigInt(f))))],typeArguments:["u32"]}):_=p.moveCall({target:"0x1::option::none",typeArguments:["u32"]}),p.moveCall({target:`${t.published_at}::pool::fetch_bins`,arguments:[p.object(r),_,p.pure.u64(l)],typeArguments:[e,s]});let y=await this._sdk.FullClient.devInspectTransactionBlock({transactionBlock:p,sender:jr("0x0")}),A=Er(y);d.push(...A),f=A.length>0?A[A.length-1].bin_id+1:void 0,c=A.length===l}return d.sort((p,_)=>p.bin_id-_.bin_id)}async getPoolTransactionList({pool_id:i,pagination_args:t,order:r="descending",full_rpc_url:e}){let{FullClient:s,sdkOptions:l}=this._sdk,d;e?d=ao(new fo({url:e})):d=s;let f={data:[],has_next_page:!1},c=50,p=t,_=t.limit||10;do{let y=await d.queryTransactionBlocksByPage({ChangedObject:i},{...p,limit:50},r);y.data.forEach((A,B)=>{let S=kr(A,B,l.dlmm_pool.package_id,i);f.data=[...f.data,...S]}),f.has_next_page=y.has_next_page,f.next_cursor=y.next_cursor,p.cursor=y.next_cursor}while(f.data.length<_&&f.has_next_page);return f.data.length>_&&(f.data=f.data.slice(0,_),f.has_next_page=!0),f.data.length>0&&(f.next_cursor=f.data[f.data.length-1].tx),f}async getRangeBinInfo(i,t,r,e){let s=[];for(let l=t;l<=r;l++){let d=await Promise.all([this.getBinInfo(i,l,e)]);s.push(...d)}return s}async getAssignPoolList(i){if(i.length===0)return[];let t=[];try{let r=await this._sdk.FullClient.batchGetObjects(i,{showContent:!0,showType:!0});for(let e of r){let s=He(e),l=`${s.id}_getDlmmPool`;this._sdk.updateCache(l,s),t.push(s)}}catch(r){return V("FetchError",r,{[te.METHOD_NAME]:"getAssignPoolList"})}return t}async getPool(i,t=!0){try{let r=`${i}_getDlmmPool`,e=this._sdk.getCache(r,t);if(e!==void 0)return e;let s=await this._sdk.FullClient.getObject({id:i,options:{showType:!0,showContent:!0}}),l=He(s);return this._sdk.updateCache(r,l),l}catch(r){return V("FetchError",r,{[te.METHOD_NAME]:"getPool",[te.REQUEST_PARAMS]:i})}}async createPoolAndAddWithPricePayload(i){let{bin_step:t,url:r,coin_type_a:e,coin_type_b:s,bin_infos:l,price_base_coin:d,price:f,lower_price:c,upper_price:p,decimals_a:_,decimals_b:y,strategy_type:A,use_bin_infos:B,base_factor:S,pool_id:O}=i,k,x,T,C=l;if(d==="coin_a")k=F.getBinIdFromPrice(c,t,!1,_,y),x=F.getBinIdFromPrice(p,t,!0,_,y),T=F.getBinIdFromPrice(f,t,!0,_,y);else{k=F.getBinIdFromPrice(Ni(1).div(p).toString(),t,!1,_,y),x=F.getBinIdFromPrice(Ni(1).div(c).toString(),t,!0,_,y),T=F.getBinIdFromPrice(Ni(1).div(f).toString(),t,!1,_,y);let X={pool_id:O,amount_a:l.amount_b,amount_b:l.amount_a,active_id:T,bin_step:t,lower_bin_id:k,upper_bin_id:x,active_bin_of_pool:void 0,strategy_type:i.strategy_type};C=await this.sdk.Position.calculateAddLiquidityInfo(X)}let N={bin_step:t,url:r,coin_type_a:e,coin_type_b:s,bin_infos:C,lower_bin_id:k,upper_bin_id:x,active_id:T,strategy_type:A,use_bin_infos:B,base_factor:S};return this.createPoolAndAddLiquidityPayload(N)}createPoolPayload(i,t){let{dlmm_pool:r}=this._sdk.sdkOptions,{bin_step:e,base_factor:s,url:l,coin_type_a:d,coin_type_b:f,active_id:c}=i;t=t||new Ke;let{registry_id:p,global_config_id:_,versioned_id:y}=qr(r),[A,B]=t.moveCall({target:`${r.published_at}::registry::create_pool_v2`,arguments:[t.object(p),t.pure.u16(e),t.pure.u16(s),t.pure.u32(Number(Fr(BigInt(c)))),t.pure.string(l||""),t.object(_),t.object(y),t.object(so)],typeArguments:[d,f]});return t.moveCall({target:`${r.published_at}::registry::destroy_receipt`,arguments:[t.object(A),B,t.object(y)],typeArguments:[d,f]}),B}createPoolAndAddLiquidityPayload(i){let{bin_step:t,base_factor:r,url:e,active_id:s,coin_type_a:l,coin_type_b:d,bin_infos:f,lower_bin_id:c,upper_bin_id:p,strategy_type:_,use_bin_infos:y}=i,A=new Ke;uo(Nr(l,!1),Nr(d,!1))&&V("InvalidCoinTypeSequence",new Error("invalid coin type sequence"),{[te.METHOD_NAME]:"createPoolAndAddLiquidityPayload",[te.REQUEST_PARAMS]:i});let B=p-c+1;B>1e3&&V("InvalidBinWidth",new Error("Width is too large"),{[te.METHOD_NAME]:"openPosition",[te.REQUEST_PARAMS]:i}),console.log("\u{1F680} ~ createPoolAndAddLiquidityPayload ~ option:",{...i,width:B});let O={pool_id:this.createPoolPayload({active_id:s,bin_step:t,base_factor:r,coin_type_a:l,coin_type_b:d},A),bin_infos:f,coin_type_a:l,coin_type_b:d,lower_bin_id:c,upper_bin_id:p,active_id:s,strategy_type:_,use_bin_infos:y,max_price_slippage:0,bin_step:t};return this.sdk.Position.addLiquidityPayload(O,A),A}};import{FullRpcUrlTestnet as co,GraphRpcUrlTestnet as ho}from"@cetusprotocol/common-sdk";var Wr={env:"testnet",full_rpc_url:co,graph_rpc_url:ho,dlmm_pool:{package_id:"0xb382224d12558da5f87624765065a8c7e8f5c899d0ee890610e2bb4e8c686be9",published_at:"0x1cdac9c678c5ec89c80409db8865c9c3f8e6207dfd988fb4ddd11e2806db0bf9",version:1,config:{registry_id:"0xdc91c4f094557b9d2a35fc6159ef32649a54c4aa9350860bf0d4b52b5f0a3990",pools_id:"0xb518b1de84a1ba1ab6c9a2d71fcdf382ef36045a4660497b3d77fb0a6df7709e",global_config_id:"0xe84ebca8d61cdd9312cec3787204d0ee1063d424a81dcda62cfb8b1887041a9f",versioned_id:"0xf8478d6dc081bc266229f25ac9c31a96b5e99ecbd82222e883368dda95829065",admin_cap_id:"0x273dbda2a1d62460a01a07831aec0fa8191a41341d634fb43f15acdb627edbce",partners_id:"0xd7ac594ed2e7756f0d4a98503dd970f314f2619a10c3613c705253a155cc9fea"}},dlmm_router:{package_id:"0xbc76d04e910452518efd5fd63d5fffe77c24855063c9cdb5501e06896bc34908",published_at:"0xe122ffbcfe5091398ba15a60e654e6589fd586b3865d5b4118292754f8cde301",version:1},faucet:{package_id:"0x14a71d857b34677a7d57e0feb303df1adb515a37780645ab763d42ce8d1a5e48",published_at:"0x14a71d857b34677a7d57e0feb303df1adb515a37780645ab763d42ce8d1a5e48",version:1}};import{asUintN as ae,CLOCK_ADDRESS as me,CoinAssist as ee,d as lt,DETAILS_KEYS as Vt,getPackagerConfigs as be}from"@cetusprotocol/common-sdk";import{Transaction as _e}from"@mysten/sui/transactions";import{normalizeSuiAddress as po}from"@mysten/sui/utils";var Ge=class{constructor(i){this._sdk=i}get sdk(){return this._sdk}buildPositionType(){return`${this._sdk.sdkOptions.dlmm_pool.package_id}::position::Position`}async getOwnerPositionList(i){let t=[];try{(await this._sdk.FullClient.getOwnedObjectsByPage(i,{options:{showType:!0,showContent:!0,showOwner:!0},filter:{StructType:this.buildPositionType()}})).data.forEach(e=>{t.push(Di(e))})}catch(r){console.log("\u{1F680} ~ PositionModule ~ getOwnerPositionList ~ error:",r),V("GetObjectError",r,{[Vt.METHOD_NAME]:"getOwnerPositionList",[Vt.REQUEST_PARAMS]:i})}return t}async getPosition(i){try{let t=await this._sdk.FullClient.getObject({id:i,options:{showType:!0,showContent:!0,showOwner:!0}});return Di(t)}catch(t){return console.log("\u{1F680} ~ PositionModule ~ getPosition ~ error:",t),V("GetObjectError",t,{[Vt.METHOD_NAME]:"getPosition",[Vt.REQUEST_PARAMS]:i})}}collectFeePayload(i,t){let{pool_id:r,position_id:e,coin_type_a:s,coin_type_b:l}=i,{dlmm_pool:d}=this.sdk.sdkOptions,{versioned_id:f,global_config_id:c}=be(d);t=t||new _e;let[p,_]=t.moveCall({target:`${d.published_at}::pool::collect_position_fee`,arguments:[t.object(r),t.object(e),t.object(c),t.object(f)],typeArguments:[s,l]}),y=ee.fromBalance(p,s,t),A=ee.fromBalance(_,l,t);return t.transferObjects([y,A],this.sdk.getSenderAddress()),t}updatePositionFeeAndRewards(i,t){let{dlmm_pool:r}=this.sdk.sdkOptions,{versioned_id:e}=be(r),{pool_id:s,position_id:l,coin_type_a:d,coin_type_b:f}=i;return t.moveCall({target:`${r.published_at}::pool::update_position_fee_and_rewards`,arguments:[t.object(s),t.pure.id(l),t.object(e),t.object(me)],typeArguments:[d,f]}),t}collectRewardPayload(i,t){let{dlmm_pool:r}=this.sdk.sdkOptions,{versioned_id:e,global_config_id:s}=be(r);return t=t||new _e,i.forEach(l=>{let{pool_id:d,position_id:f,reward_coins:c,coin_type_a:p,coin_type_b:_}=l;c.forEach(y=>{let A=t.moveCall({target:`${r.published_at}::pool::collect_position_reward`,arguments:[t.object(d),t.object(f),t.object(s),t.object(e)],typeArguments:[p,_,y]}),B=ee.fromBalance(A,y,t);t.transferObjects([B],this.sdk.getSenderAddress())})}),t}collectRewardAndFeePayload(i,t){return t=t||new _e,i.forEach(r=>{let{pool_id:e,position_id:s,reward_coins:l,coin_type_a:d,coin_type_b:f}=r;this.updatePositionFeeAndRewards({pool_id:e,position_id:s,coin_type_a:d,coin_type_b:f},t),this.collectFeePayload({pool_id:e,position_id:s,coin_type_a:d,coin_type_b:f},t),this.collectRewardPayload([{pool_id:e,position_id:s,reward_coins:l,coin_type_a:d,coin_type_b:f}],t)}),t}validateActiveIdSlippage(i,t){let{pool_id:r,active_id:e,max_price_slippage:s,bin_step:l,coin_type_a:d,coin_type_b:f}=i,{dlmm_router:c}=this.sdk.sdkOptions,p=F.getBinShift(e,l,s),_=Number(ae(BigInt(e)));return t.moveCall({target:`${c.published_at}::utils::validate_active_id_slippage`,arguments:[typeof r=="string"?t.object(r):r,t.pure.u32(Number(_)),t.pure.u32(Number(p))],typeArguments:[d,f]}),t}closePositionPayload(i,t){t=t||new _e;let{coin_a_obj:r,coin_b_obj:e}=this.closePositionNoTransferPayload(i,t);return t.transferObjects([r,e],this.sdk.getSenderAddress()),t}closePositionNoTransferPayload(i,t){let{pool_id:r,position_id:e,reward_coins:s,coin_type_a:l,coin_type_b:d}=i,{dlmm_pool:f}=this.sdk.sdkOptions,{versioned_id:c,global_config_id:p}=be(f);t=t||new _e,this.updatePositionFeeAndRewards({pool_id:r,position_id:e,coin_type_a:l,coin_type_b:d},t),this.collectRewardPayload([{pool_id:r,position_id:e,reward_coins:s,coin_type_a:l,coin_type_b:d}],t);let[_,y,A]=t.moveCall({target:`${f.published_at}::pool::close_position`,arguments:[t.object(r),t.object(e),t.object(p),t.object(c),t.object(me)],typeArguments:[l,d]}),B=ee.fromBalance(y,l,t),S=ee.fromBalance(A,d,t);return t.moveCall({target:`${f.published_at}::pool::destroy_close_position_cert`,arguments:[_,t.object(c)],typeArguments:[]}),{coin_a_obj:B,coin_b_obj:S}}async getActiveBinIfInRange(i,t,r,e,s,l=!1){if(e<=r&&e>=t)return await this._sdk.Pool.getBinInfo(i,e,s,l)}calculateRemoveLiquidityInfo(i){let{bins:t,active_id:r,coin_amount:e}=i,s="fix_amount_a"in i,l=t.filter(y=>y.bin_id<r),d=t.filter(y=>y.bin_id>r),f=lt(0),c=lt(0),p=[];if(s){p=[...t];let{fix_amount_a:y}=i,A=t.find(O=>O.bin_id===r),B=d.reduce((O,k)=>lt(O).plus(k.amount_a),lt(0)).add(A?.amount_a||"0"),S=l.reduce((O,k)=>lt(O).plus(k.amount_b),lt(0)).add(A?.amount_b||"0");f=y?B:S,c=lt(e).gte(f)?lt(1):lt(e).div(f)}else{let{is_only_a:y}=i;p=y?d:l,f=p.reduce((A,B)=>lt(A).plus(y?B.amount_a:B.amount_b),lt(0)),c=lt(e).gte(f)?lt(1):lt(e).div(f)}return lt(f).isZero()?V("InsufficientLiquidity",new Error("Insufficient liquidity"),{[Vt.METHOD_NAME]:"calculateRemoveLiquidityResult",[Vt.REQUEST_PARAMS]:i}):F.processBinsByRate([...p],c.toFixed())}async calculateAddLiquidityInfo(i){let t="fix_amount_a"in i,{active_id:r,bin_step:e,lower_bin_id:s,upper_bin_id:l,active_bin_of_pool:d,strategy_type:f,pool_id:c}=i,p;if(t){let{coin_amount:_,fix_amount_a:y}=i;p=Ce.autoFillCoinByStrategyV2(r,e,_,y,s,l,f,d)}else p=Ce.toAmountsBothSideByStrategy(r,e,s,l,i.amount_a,i.amount_b,f,d);if(d&&c){let _=p.bins.findIndex(y=>y.bin_id===r);if(_!==-1){let y=await this._sdk.Pool.getPool(c,!1);if(y){let{fees_a:A,fees_b:B}=Qe.getCompositionFees(d,p.bins[_],y.variable_parameters),S=p.bins[_];S.amount_a=lt(S.amount_a).sub(A).toFixed(0),S.amount_b=lt(S.amount_b).sub(B).toFixed(0),p.bins[_]=S}}}return p}removeLiquidityPayload(i){let t=new _e,{coin_a_obj:r,coin_b_obj:e}=this.removeLiquidityNoTransferPayload(i,t);return t.transferObjects([r,e],this.sdk.getSenderAddress()),t}removeLiquidityNoTransferPayload(i,t){let{pool_id:r,position_id:e,bin_infos:s,reward_coins:l,slippage:d,coin_type_a:f,coin_type_b:c,active_id:p,collect_fee:_,bin_step:y,remove_percent:A}=i,{dlmm_pool:B}=this.sdk.sdkOptions,{bins:S}=s;(_||l.length>0)&&this.updatePositionFeeAndRewards({pool_id:r,position_id:e,coin_type_a:f,coin_type_b:c},t),_&&this.collectFeePayload({pool_id:r,position_id:e,coin_type_a:f,coin_type_b:c},t),this.collectRewardPayload([{pool_id:r,position_id:e,reward_coins:l,coin_type_a:f,coin_type_b:c}],t);let{versioned_id:O,global_config_id:k}=be(B);if(A){let x=ae(BigInt(S[0].bin_id)),T=ae(BigInt(S[S.length-1].bin_id)),C=Number(lt(A).mul(1e4).toFixed(0)),[j,N]=t.moveCall({target:`${B.published_at}::pool::remove_liquidity_by_percent`,arguments:[t.object(r),t.object(e),t.pure.u32(Number(x)),t.pure.u32(Number(T)),t.pure.u16(C),t.object(k),t.object(O),t.object(me)],typeArguments:[f,c]}),X=ee.fromBalance(j,f,t),tt=ee.fromBalance(N,c,t);return this.validateActiveIdSlippage({pool_id:r,active_id:p,max_price_slippage:d,bin_step:y,coin_type_a:f,coin_type_b:c},t),{coin_a_obj:X,coin_b_obj:tt}}else{let x=t.pure.vector("u32",S.map(tt=>Number(ae(BigInt(tt.bin_id))))),T=t.pure.vector("u128",S.map(tt=>tt.liquidity)),[C,j]=t.moveCall({target:`${B.published_at}::pool::remove_liquidity`,arguments:[t.object(r),t.object(e),x,T,t.object(k),t.object(O),t.object(me)],typeArguments:[f,c]});this.validateActiveIdSlippage({pool_id:r,active_id:p,max_price_slippage:d,bin_step:y,coin_type_a:f,coin_type_b:c},t);let N=ee.fromBalance(C,f,t),X=ee.fromBalance(j,c,t);return{coin_a_obj:N,coin_b_obj:X}}}async addLiquidityWithPricePayload(i){let{pool_id:t,bin_infos:r,coin_type_a:e,coin_type_b:s,price_base_coin:l,price:d,lower_price:f,upper_price:c,bin_step:p,strategy_type:_,active_bin_of_pool:y,decimals_a:A,decimals_b:B,use_bin_infos:S,max_price_slippage:O}=i,k,x,T,C=r;if(l==="coin_a")k=F.getBinIdFromPrice(f,p,!1,A,B),x=F.getBinIdFromPrice(c,p,!0,A,B),T=F.getBinIdFromPrice(d,p,!0,A,B);else{k=F.getBinIdFromPrice(lt(1).div(c).toString(),p,!1,A,B),x=F.getBinIdFromPrice(lt(1).div(f).toString(),p,!0,A,B),T=F.getBinIdFromPrice(lt(1).div(d).toString(),p,!1,A,B);let X={amount_a:r.amount_b,amount_b:r.amount_a,active_id:T,bin_step:p,lower_bin_id:k,upper_bin_id:x,active_bin_of_pool:y,strategy_type:_};C=await this.sdk.Position.calculateAddLiquidityInfo(X)}let N={pool_id:t,active_id:T,bin_infos:C,coin_type_a:e,coin_type_b:s,lower_bin_id:k,upper_bin_id:x,strategy_type:_,use_bin_infos:S,max_price_slippage:O,bin_step:p};return this.addLiquidityPayload(N)}addLiquidityPayload(i,t){let{pool_id:r,bin_infos:e,coin_type_a:s,coin_type_b:l,active_id:d,strategy_type:f,max_price_slippage:c,bin_step:p,use_bin_infos:_=!1,coin_object_id_a:y,coin_object_id_b:A}=i;t=t||new _e;let B="lower_bin_id"in i,S=[];if(B){let O=F.splitBinLiquidityInfo(e,i.lower_bin_id,i.upper_bin_id);S.push(...O)}else{let O=i.position_id;S.push(e),(i.collect_fee||i.reward_coins.length>0)&&this.updatePositionFeeAndRewards({pool_id:r,position_id:O,coin_type_a:s,coin_type_b:l},t),i.collect_fee&&this.collectFeePayload({pool_id:r,position_id:O,coin_type_a:s,coin_type_b:l},t),i.reward_coins.length>0&&this.collectRewardPayload([{pool_id:r,position_id:O,reward_coins:i.reward_coins,coin_type_a:s,coin_type_b:l}],t)}return S.forEach((O,k)=>{console.log("\u{1F680} ~ PositionModule ~ addLiquidityPayload ~ liquidity_bin:",k,O);let{amount_a:x,amount_b:T,bins:C}=O,j=y||ee.buildCoinWithBalance(BigInt(x),s,t),N=A||ee.buildCoinWithBalance(BigInt(T),l,t);_?this.addLiquidityInternal({pool_id:r,coin_type_a:s,coin_type_b:l,active_id:d,liquidity_bin:O,tx:t,coin_a_obj_id:j,coin_b_obj_id:N,position_id:B?void 0:i.position_id,max_price_slippage:c,bin_step:p}):this.addLiquidityStrategyInternal({pool_id:r,coin_type_a:s,coin_type_b:l,active_id:d,liquidity_bin:O,tx:t,max_price_slippage:c,bin_step:p,coin_a_obj_id:j,coin_b_obj_id:N,strategy_type:f,position_id:B?void 0:i.position_id})}),t}addLiquidityStrategyInternal(i){let{max_price_slippage:t,bin_step:r,position_id:e,pool_id:s,coin_type_a:l,coin_type_b:d,active_id:f,liquidity_bin:c,tx:p,coin_a_obj_id:_,coin_b_obj_id:y,strategy_type:A}=i,{dlmm_pool:B,dlmm_router:S}=this.sdk.sdkOptions,{versioned_id:O,global_config_id:k}=be(B),{bins:x,amount_a:T,amount_b:C}=c,j=e,N=x[0].bin_id,X=x[x.length-1].bin_id,tt=ae(BigInt(N)),it=Number(ae(BigInt(f))),st=F.getBinShift(f,r,t),G=xr(A);if(e===void 0){let nt=X-N+1;nt>1e3&&V("InvalidBinWidth",new Error("Width is too large"),{[Vt.METHOD_NAME]:"openPosition"}),j=p.moveCall({target:`${S.published_at}::${G}::open_position`,arguments:[typeof s=="string"?p.object(s):s,_,y,p.pure.u64(T),p.pure.u64(C),p.pure.u32(Number(tt)),p.pure.u16(Number(nt)),p.pure.u32(Number(it)),p.pure.u32(Number(st)),p.object(k),p.object(O),p.object(me)],typeArguments:[l,d]})}else{let nt=x.filter(u=>u.amount_a!=="0"||u.amount_b!=="0");if(nt.length===0)return V("InvalidParams",new Error("No bins to add liquidity"),{[Vt.METHOD_NAME]:"addLiquidityStrategyInternal",[Vt.REQUEST_PARAMS]:i});let v=ae(BigInt(nt[0].bin_id)),o=ae(BigInt(nt[nt.length-1].bin_id));p.moveCall({target:`${S.published_at}::${G}::add_liquidity`,arguments:[typeof s=="string"?p.object(s):s,p.object(e),_,y,p.pure.u64(T),p.pure.u64(C),p.pure.u32(Number(v)),p.pure.u32(Number(o)),p.pure.u32(Number(it)),p.pure.u32(Number(st)),p.object(k),p.object(O),p.object(me)],typeArguments:[l,d]})}return j?p.transferObjects([j,_,y],this.sdk.getSenderAddress()):p.transferObjects([_,y],this.sdk.getSenderAddress()),p}addLiquidityInternal(i){let{position_id:t,pool_id:r,coin_type_a:e,coin_type_b:s,active_id:l,liquidity_bin:d,tx:f,coin_a_obj_id:c,coin_b_obj_id:p,max_price_slippage:_,bin_step:y}=i,{bins:A}=d,{dlmm_pool:B,dlmm_router:S}=this.sdk.sdkOptions,{versioned_id:O,global_config_id:k}=be(B),x=f.pure.vector("u64",A.map(X=>X.amount_a)),T=f.pure.vector("u64",A.map(X=>X.amount_b)),C=f.makeMoveVec({elements:A.map(X=>f.pure.u32(Number(ae(BigInt(X.bin_id))))),type:"u32"}),j=d.bins[0].bin_id,N=d.bins[d.bins.length-1].bin_id;if(t===void 0){N-j+1>1e3&&V("InvalidBinWidth",new Error("Width is too large"),{[Vt.METHOD_NAME]:"openPosition"});let tt=f.moveCall({target:`${S.published_at}::add_liquidity::open_position`,arguments:[typeof r=="string"?f.object(r):r,c,p,C,x,T,f.object(k),f.object(O),f.object(me)],typeArguments:[e,s]});l>=j&&l<=N&&this.validateActiveIdSlippage({pool_id:r,active_id:l,max_price_slippage:_,bin_step:y,coin_type_a:e,coin_type_b:s},f),f.transferObjects([c,p,tt],this.sdk.getSenderAddress())}else f.moveCall({target:`${S.published_at}::add_liquidity::add_liquidity`,arguments:[typeof r=="string"?f.object(r):r,f.object(t),c,p,C,x,T,f.object(k),f.object(O),f.object(me)],typeArguments:[e,s]}),l>=j&&l<=N&&this.validateActiveIdSlippage({pool_id:r,active_id:l,max_price_slippage:_,bin_step:y,coin_type_a:e,coin_type_b:s},f),f.transferObjects([c,p],this.sdk.getSenderAddress());return f}async fetchPositionFeeAndReward(i){let t=new _e;this.collectRewardAndFeePayload(i,t);let r=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:t,sender:po("0x0")});if(r.error!=null)return V("FetchError",new Error(r.error),{[Vt.METHOD_NAME]:"fetchPositionFeeAndReward",[Vt.REQUEST_PARAMS]:{options:i,totalOptions:i.length}});let e=Or(r),s=Tr(r);return{feeData:e,rewardData:s}}};import{Transaction as Zr}from"@mysten/sui/transactions";import{CLOCK_ADDRESS as Li,CoinAssist as mo,d as Ur,DETAILS_KEYS as Ve,getPackagerConfigs as Hr}from"@cetusprotocol/common-sdk";import{normalizeSuiAddress as _o}from"@mysten/sui/utils";var Xe=class{constructor(i){this._sdk=i}get sdk(){return this._sdk}async preSwapQuote(i){let{dlmm_pool:t}=this._sdk.sdkOptions,{pool_id:r,coin_type_a:e,coin_type_b:s,a2b:l,by_amount_in:d,in_amount:f}=i,{versioned_id:c,global_config_id:p}=Hr(t),_=new Zr;_.moveCall({target:`${t.published_at}::pool::flash_swap`,arguments:[_.object(r),_.pure.bool(l),_.pure.bool(d),_.pure.u64(f),_.object(p),_.object(c),_.object(Li)],typeArguments:[e,s]});let y=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:_,sender:_o("0x0")});if(y.error!=null)return V("FetchError",new Error(y.error),{[Ve.METHOD_NAME]:"fetchSwapQuote",[Ve.REQUEST_PARAMS]:i});let A=Cr(y,l);return A==null?V("FetchError",new Error("No quote info"),{[Ve.METHOD_NAME]:"preSwapQuote",[Ve.REQUEST_PARAMS]:i}):(A.a2b=l,A)}swapPayload(i){let{dlmm_pool:t,dlmm_router:r}=this._sdk.sdkOptions,{quote_obj:e,coin_type_a:s,coin_type_b:l,by_amount_in:d,slippage:f,partner:c}=i,{pool_id:p,in_amount:_,out_amount:y,a2b:A}=e,B=new Zr,S=d?_:Ur(_).mul(1+f).toFixed(0),O=d?Ur(y).mul(1-f).toFixed(0):y,k=mo.buildCoinWithBalance(BigInt(S),A?s:l,B),{versioned_id:x,global_config_id:T}=Hr(t);return console.log("\u{1F680} ~ SwapModule ~ option:",{...i,in_amount_limit:S,out_amount_limit:O}),c?B.moveCall({target:`${r.published_at}::swap::${A?"swap_a2b_with_partner":"swap_b2a_with_partner"}`,arguments:[B.object(p),B.object(c),k,B.pure.bool(d),B.pure.u64(BigInt(d?_:y)),B.pure.u64(BigInt(d?O:S)),B.object(T),B.object(x),B.object(Li)],typeArguments:[s,l]}):B.moveCall({target:`${r.published_at}::swap::${A?"swap_a2b":"swap_b2a"}`,arguments:[B.object(p),k,B.pure.bool(d),B.pure.u64(BigInt(d?_:y)),B.pure.u64(BigInt(d?O:S)),B.object(T),B.object(x),B.object(Li)],typeArguments:[s,l]}),B.transferObjects([k],this.sdk.getSenderAddress()),B}};import{Transaction as Je}from"@mysten/sui/transactions";import{CLOCK_ADDRESS as go,d as Qr,DETAILS_KEYS as Ht,fixCoinType as bo,getObjectFields as qi,getPackagerConfigs as ke}from"@cetusprotocol/common-sdk";var Ye=class{constructor(i){this._sdk=i}get sdk(){return this._sdk}async getPartnerList(){let i=[],{dlmm_pool:t}=this._sdk.sdkOptions,{partners_id:r}=ke(t);try{let e=await this._sdk.FullClient.getObject({id:r,options:{showContent:!0}}),l=qi(e).partners.fields.contents.map(d=>d.fields.value);l.length>0&&(await this._sdk.FullClient.batchGetObjects(l,{showContent:!0,showType:!0})).forEach(f=>{let c=Ri(f);i.push(c)})}catch(e){return V("FetchError",e,{[Ht.METHOD_NAME]:"getPartnerList",[Ht.REQUEST_PARAMS]:r})}return i}async getPartnerCapId(i,t){let{dlmm_pool:r}=this._sdk.sdkOptions;try{let e=`partner_cap_id_${i}_${t}`,s=this._sdk.getCache(e);if(s)return s;let l=await this._sdk.FullClient.getOwnedObjects({owner:i,options:{showContent:!0,showType:!0},filter:{StructType:`${r.package_id}::partner::PartnerCap`}}),d;return l.data.forEach(f=>{let c=qi(f);c.partner_id===t&&(d=c.id.id,this._sdk.updateCache(e,d))}),d||V("NotFound",new Error("Partner cap not found"),{[Ht.METHOD_NAME]:"getPartnerCapId",[Ht.REQUEST_PARAMS]:{owner:i,partner_id:t}})}catch(e){return V("FetchError",e,{[Ht.METHOD_NAME]:"getPartnerCapId",[Ht.REQUEST_PARAMS]:{owner:i,partner_id:t}})}}async getPartnerBalance(i){try{let t=await this._sdk.FullClient.getDynamicFieldsByPage(i),r=[],e=t.data.map(s=>s.objectId);return e.length>0&&(await this._sdk.FullClient.batchGetObjects(e,{showContent:!0,showType:!0})).forEach(l=>{let d=qi(l);console.log(d),r.push({coin_type:bo(d.name,!1),balance:d.value})}),r}catch(t){return V("FetchError",t,{[Ht.METHOD_NAME]:"getPartnerBalance",[Ht.REQUEST_PARAMS]:i})}}async getPartner(i){try{let t=await this._sdk.FullClient.getObject({id:i,options:{showContent:!0}});return Ri(t)}catch(t){return V("FetchError",t,{[Ht.METHOD_NAME]:"getPartner",[Ht.REQUEST_PARAMS]:i})}}updateRefFeeRatePayload(i,t){let{dlmm_pool:r}=this._sdk.sdkOptions,{partner_id:e,ref_fee_rate:s}=i,{global_config_id:l,versioned_id:d}=ke(r);t=t||new Je;let f=Qr(s).mul(1e4);return f.gt(1e4)?V("InvalidParams",new Error("ref_fee_rate is cannot be greater than 1"),{[Ht.METHOD_NAME]:"updateRefFeeRatePayload",[Ht.REQUEST_PARAMS]:i}):(t.moveCall({target:`${r.published_at}::partner::update_ref_fee_rate`,arguments:[t.object(e),t.pure.u64(f.toNumber()),t.object(l),t.object(d)],typeArguments:[]}),t)}async claimRefFeePayload(i){let{partner_id:t,partner_cap_id:r,fee_coin_types:e}=i,{dlmm_pool:s}=this._sdk.sdkOptions,{versioned_id:l}=ke(s),d=new Je,f=r;return f||(f=await this.getPartnerCapId(this._sdk.getSenderAddress(),t)),e.forEach(c=>{d.moveCall({target:`${s.published_at}::partner::claim_ref_fee`,arguments:[d.object(t),d.object(f),d.object(l)],typeArguments:[c]})}),d}updateTimeRangePayload(i,t){let{dlmm_pool:r}=this._sdk.sdkOptions,{partner_id:e,start_time:s,end_time:l}=i,{global_config_id:d,versioned_id:f}=ke(r);t=t||new Je;let c=s>1e12?Math.floor(s/1e3):s,p=l>1e12?Math.floor(l/1e3):l;return p<=c?V("InvalidParams",new Error("end_time must be greater than start_time"),{[Ht.METHOD_NAME]:"createPartnerPayload",[Ht.REQUEST_PARAMS]:i}):(t.moveCall({target:`${r.published_at}::partner::update_time_range`,arguments:[t.object(e),t.pure.u64(c),t.pure.u64(p),t.object(d),t.object(f),t.object(go)],typeArguments:[]}),t)}createPartnerPayload(i){let{dlmm_pool:t}=this._sdk.sdkOptions,{name:r,ref_fee_rate:e,start_time:s,end_time:l,recipient:d}=i,{partners_id:f,global_config_id:c,versioned_id:p}=ke(t),_=new Je,y=Qr(e).mul(1e4);if(y.gt(1e4))return V("InvalidParams",new Error("ref_fee_rate is cannot be greater than 1"),{[Ht.METHOD_NAME]:"createPartnerPayload",[Ht.REQUEST_PARAMS]:i});let A=s>1e12?Math.floor(s/1e3):s,B=l>1e12?Math.floor(l/1e3):l;return B<=A?V("InvalidParams",new Error("end_time must be greater than start_time"),{[Ht.METHOD_NAME]:"createPartnerPayload",[Ht.REQUEST_PARAMS]:i}):(_.moveCall({target:`${t.published_at}::partner::create_partner`,arguments:[_.object(f),_.pure.string(r),_.pure.u64(y.toNumber()),_.pure.u64(A),_.pure.u64(B),_.pure.address(d),_.object(c),_.object(p)],typeArguments:[]}),_)}};var Zi=Mi(xe());import{Transaction as ji}from"@mysten/sui/transactions";import{CLOCK_ADDRESS as Kr,CoinAssist as wo,d as Be,getObjectFields as vo,getPackagerConfigs as Wi,MathUtil as $r}from"@cetusprotocol/common-sdk";var ti=class{constructor(i){this._sdk=i}get sdk(){return this._sdk}async getRewardPeriodEmission(i,t,r){let e=await this._sdk.FullClient.getDynamicFieldsByPage(i),s=[],l=e.data.map(p=>p.objectId);l.length>0&&(await this._sdk.FullClient.batchGetObjects(l,{showContent:!0})).forEach(_=>{let y=vo(_),A=$r.u128ToI128(new Zi.default(y.value.fields.value.fields.bits)).toString(),B=y.name,S=new Date(Number(B)*1e3).toLocaleString(),k={emissions_per_second:"0",emissions_per_day:"0",emissions_per:$r.fromX64(new Zi.default(A)).toString(),time:B,visualized_time:S};s.push(k)});let d=s.sort((p,_)=>Number(p.time)-Number(_.time)),f=[];f.push({emissions_per_second:t,emissions_per_day:Be(t).mul(3600*24).toString(),emissions_per:"0",time:r.toString(),visualized_time:new Date(r*1e3).toLocaleString()});let c=t;for(let p=0;p<d.length;p++){let _=d[p];if(Be(_.time).lte(r))continue;c=Be(c).add(Be(_.emissions_per)).toString();let y=Be(c).mul(3600*24).toString();Be(c).lt(0)?(_.emissions_per_second="0",_.emissions_per_day="0"):(_.emissions_per_second=c,_.emissions_per_day=y),f.push(_)}return f}addRewardPayload(i,t){t=t||new ji;let{dlmm_pool:r}=this._sdk.sdkOptions,{global_config_id:e,versioned_id:s}=Wi(r),{pool_id:l,reward_coin_type:d,reward_amount:f,start_time_seconds:c,end_time_seconds:p,coin_type_a:_,coin_type_b:y}=i,A=wo.buildCoinWithBalance(BigInt(f),d,t);return t.pure.option("u64",c),t.moveCall({target:`${r.published_at}::pool::add_reward`,arguments:[t.object(l),A,t.pure.option("u64",c),t.pure.u64(p),t.object(e),t.object(s),t.object(Kr)],typeArguments:[_,y,d]}),t}initRewardPayload(i,t){t=t||new ji;let{dlmm_pool:r}=this._sdk.sdkOptions,{global_config_id:e,versioned_id:s}=Wi(r),{pool_id:l,reward_coin_types:d,coin_type_a:f,coin_type_b:c}=i;return d.forEach(p=>{t.moveCall({target:`${r.published_at}::pool::initialize_reward`,arguments:[t.object(l),t.object(e),t.object(s),t.object(Kr)],typeArguments:[f,c,p]})}),t}buildRewardAccessPayload(i,t){t=t||new ji;let{dlmm_pool:r}=this._sdk.sdkOptions,{global_config_id:e,versioned_id:s}=Wi(r),{pool_id:l,type:d,coin_type_a:f,coin_type_b:c}=i;return t.moveCall({target:`${r.published_at}::pool::${d==="to_public"?"make_reward_public":"make_reward_private"}`,arguments:[t.object(l),t.object(e),t.object(s)],typeArguments:[f,c]}),t}};import{Transaction as yo}from"@mysten/sui/transactions";import{DETAILS_KEYS as zr,fixCoinType as Mo,getObjectFields as Ui,getPackagerConfigs as Gr}from"@cetusprotocol/common-sdk";var ei=class{constructor(i){this._sdk=i}get sdk(){return this._sdk}buildRewardWhiteListPayload(i,t){t=t||new yo;let{dlmm_pool:r}=this._sdk.sdkOptions,{global_config_id:e,versioned_id:s}=Gr(r),{reward_coin_types:l,type:d}=i;return l.forEach(f=>{t.moveCall({target:`${r.published_at}::config::${d==="add"?"add_reward_whitelist":"remove_reward_whitelist"}`,arguments:[t.object(e),t.object(s)],typeArguments:[f]})}),t}async getBinStepConfigList(i){let t=await this._sdk.FullClient.getDynamicFieldsByPage(i),r=[],e=t.data.map(s=>s.objectId);return e.length>0&&(await this._sdk.FullClient.batchGetObjects(e,{showContent:!0})).forEach(l=>{let f={...Ui(l).value.fields};r.push(f)}),r}async getDlmmGlobalConfig(){let{dlmm_pool:i}=this._sdk.sdkOptions,{global_config_id:t}=Gr(i);try{let r=await this._sdk.FullClient.getObject({id:t,options:{showContent:!0}}),e=Ui(r),s=e.reward_config.fields,l=s.reward_white_list?.fields?.contents?.map(f=>Mo(f.fields.key.fields.name,!1))||[];return{id:e.id.id,acl:{id:e.acl.fields.permissions.fields.id.id,size:e.acl.fields.permissions.fields.size},allowed_list:{id:e.allowed_list.fields.id.id,size:e.allowed_list.fields.size},denied_list:{id:e.denied_list.fields.id.id,size:e.denied_list.fields.size},bin_steps:{id:e.bin_steps.fields.id.id,size:e.bin_steps.fields.size},reward_white_list:l,blocked_position:{id:e.restriction.fields.blocked_position.fields.permissions.fields.id.id,size:e.restriction.fields.blocked_position.fields.permissions.fields.size},blocked_user:{id:e.restriction.fields.blocked_user.fields.permissions.fields.id.id,size:e.restriction.fields.blocked_user.fields.permissions.fields.size},min_reward_duration:Number(s.min_reward_duration),non_manager_initialize_reward_cap:Number(s.manager_reserved_reward_init_slots),reward_public:s.reward_public}}catch(r){return console.log("fetchGlobalConfig error: ",r),V("FetchError",r,{[zr.METHOD_NAME]:"getBinStepConfigs",[zr.REQUEST_PARAMS]:t})}}async fetchDlmmSdkConfigs(){let{dlmm_pool:i}=this._sdk.sdkOptions,t={registry_id:"",pools_id:"",global_config_id:"",versioned_id:"",admin_cap_id:"",partners_id:""},e=(await this._sdk.FullClient.getObject({id:i.package_id,options:{showContent:!0,showPreviousTransaction:!0}})).data?.previousTransaction;(await this._sdk.FullClient.getTransactionBlock({digest:e,options:{showEvents:!0}})).events?.forEach(f=>{let c=f.type,p=f.parsedJson;c.includes("versioned::InitEvent")&&(t.versioned_id=p.versioned),c.includes("partner::InitPartnerEvent")&&(t.partners_id=p.partners_id),c.includes("config::InitEvent")&&(t.global_config_id=p.config_id),c.includes("admin_cap::InitEvent")&&(t.admin_cap_id=p.admin_cap_id),c.includes("registry::RegistryEvent")&&(t.registry_id=p.pools_id)});let l=await this._sdk.FullClient.getObject({id:t.registry_id,options:{showContent:!0}}),d=Ui(l);return t.pools_id=d.pools.fields.id.id,t}};var ii=class n extends Po{constructor(i){super(i),this._pool=new ze(this),this._position=new Ge(this),this._swap=new Xe(this),this._partner=new Ye(this),this._reward=new ti(this),this._config=new ei(this)}get Pool(){return this._pool}get Position(){return this._position}get Swap(){return this._swap}get Partner(){return this._partner}get Reward(){return this._reward}get Config(){return this._config}static createSDK(i){let{env:t="mainnet"}=i;return t==="mainnet"?n.createCustomSDK({...ar,...i}):n.createCustomSDK({...Wr,...i})}static createCustomSDK(i){return new n(i)}};var Pl=ii;export{Jt as BASIS_POINT,he as BASIS_POINT_MAX,Me as BIN_BOUND,F as BinUtils,ii as CetusDlmmSDK,Oe as DEFAULT_MAX_WEIGHT,ye as DEFAULT_MIN_WEIGHT,Pr as FEE_PRECISION,Qe as FeeUtils,Dr as IlmUtils,ko as MAX_BIN_ID,ce as MAX_BIN_PER_POSITION,Oi as MAX_FEE_RATE,Co as MIN_BIN_ID,Ti as ONE,ze as PoolModule,xo as REWARD_PERIOD,Ro as REWARD_PERIOD_START_AT,q as SCALE_OFFSET,Ze as StrategyType,Ce as StrategyUtils,Yt as WeightUtils,Rr as buildPoolKey,Pl as default,ar as dlmmMainnet,Wr as dlmmTestnet,gs as generateRewardSchedule,xr as getRouterModule,Fi as parseBinInfo,Er as parseBinInfoList,ws as parseCurrentRewardPeriodEmission,Ir as parseDlmmBasePool,He as parseDlmmPool,Di as parseDlmmPosition,ms as parseLiquidityShares,Ri as parsePartner,kr as parsePoolTransactionInfo,bs as parseRewardPeriodEmission,_s as parseStrategyType,Or as parsedDlmmPosFeeData,Tr as parsedDlmmPosRewardData,Cr as parsedSwapQuoteData,oo as poolFilterEvenTypes,Te as safeAmount,oe as safeMulAmount};
2
2
  /*! Bundled license information:
3
3
 
4
4
  decimal.js/decimal.mjs: