@cetusprotocol/dlmm-sdk 0.0.0-experimental-20250925173459
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/.turbo/turbo-build.log +10444 -0
- package/README.md +654 -0
- package/dist/index.d.mts +1050 -0
- package/dist/index.d.ts +1050 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +13 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +35 -0
- package/src/config/index.ts +2 -0
- package/src/config/mainnet.ts +25 -0
- package/src/config/testnet.ts +30 -0
- package/src/errors/errors.ts +40 -0
- package/src/index.ts +8 -0
- package/src/modules/configModule.ts +184 -0
- package/src/modules/index.ts +1 -0
- package/src/modules/partnerModule.ts +302 -0
- package/src/modules/poolModule.ts +578 -0
- package/src/modules/positionModule.ts +882 -0
- package/src/modules/rewardModule.ts +174 -0
- package/src/modules/swapModule.ts +129 -0
- package/src/sdk.ts +88 -0
- package/src/types/constants.ts +23 -0
- package/src/types/dlmm.ts +445 -0
- package/src/types/ilm.ts +33 -0
- package/src/types/index.ts +3 -0
- package/src/utils/binUtils.ts +552 -0
- package/src/utils/feeUtils.ts +92 -0
- package/src/utils/ilmUtils.ts +187 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/parseData.ts +519 -0
- package/src/utils/strategyUtils.ts +121 -0
- package/src/utils/weightUtils.ts +510 -0
- package/tests/add_liquidity_bidask.test.ts +180 -0
- package/tests/add_liquidity_curve.test.ts +244 -0
- package/tests/add_liquidity_spot.test.ts +262 -0
- package/tests/bin.test.ts +80 -0
- package/tests/config.test.ts +73 -0
- package/tests/ilm.test.ts +31 -0
- package/tests/partner.test.ts +74 -0
- package/tests/pool.test.ts +174 -0
- package/tests/position.test.ts +76 -0
- package/tests/remove_liquidity.test.ts +137 -0
- package/tests/swap.test.ts +96 -0
- package/tests/tsconfig.json +26 -0
- package/tsconfig.json +5 -0
- package/tsup.config.ts +9 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";var Cr=Object.create;var Oe=Object.defineProperty;var Tr=Object.getOwnPropertyDescriptor;var xr=Object.getOwnPropertyNames;var kr=Object.getPrototypeOf,Rr=Object.prototype.hasOwnProperty;var Fr=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Dr=(n,e)=>{for(var t in e)Oe(n,t,{get:e[t],enumerable:!0})},rr=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of xr(e))!Rr.call(n,i)&&i!==t&&Oe(n,i,{get:()=>e[i],enumerable:!(r=Tr(e,i))||r.enumerable});return n};var bi=(n,e,t)=>(t=n!=null?Cr(kr(n)):{},rr(e||!n||!n.__esModule?Oe(t,"default",{value:n,enumerable:!0}):t,n)),Nr=n=>rr(Oe({},"__esModule",{value:!0}),n);var Ce=Fr((sr,vi)=>{"use strict";(function(n,e){"use strict";function t(v,o){if(!v)throw new Error(o||"Assertion failed")}function r(v,o){v.super_=o;var l=function(){};l.prototype=o.prototype,v.prototype=new l,v.prototype.constructor=v}function i(v,o,l){if(i.isBN(v))return v;this.negative=0,this.words=null,this.length=0,this.red=null,v!==null&&((o==="le"||o==="be")&&(l=o,o=10),this._init(v||0,o||10,l||"be"))}typeof n=="object"?n.exports=i:e.BN=i,i.BN=i,i.wordSize=26;var s;try{typeof window<"u"&&typeof window.Buffer<"u"?s=window.Buffer:s=require("buffer").Buffer}catch{}i.isBN=function(o){return o instanceof i?!0:o!==null&&typeof o=="object"&&o.constructor.wordSize===i.wordSize&&Array.isArray(o.words)},i.max=function(o,l){return o.cmp(l)>0?o:l},i.min=function(o,l){return o.cmp(l)<0?o:l},i.prototype._init=function(o,l,c){if(typeof o=="number")return this._initNumber(o,l,c);if(typeof o=="object")return this._initArray(o,l,c);l==="hex"&&(l=16),t(l===(l|0)&&l>=2&&l<=36),o=o.toString().replace(/\s+/g,"");var m=0;o[0]==="-"&&(m++,this.negative=1),m<o.length&&(l===16?this._parseHex(o,m,c):(this._parseBase(o,l,m),c==="le"&&this._initArray(this.toArray(),l,c)))},i.prototype._initNumber=function(o,l,c){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),c==="le"&&this._initArray(this.toArray(),l,c)},i.prototype._initArray=function(o,l,c){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 g,M,P=0;if(c==="be")for(m=o.length-1,g=0;m>=0;m-=3)M=o[m]|o[m-1]<<8|o[m-2]<<16,this.words[g]|=M<<P&67108863,this.words[g+1]=M>>>26-P&67108863,P+=24,P>=26&&(P-=26,g++);else if(c==="le")for(m=0,g=0;m<o.length;m+=3)M=o[m]|o[m+1]<<8|o[m+2]<<16,this.words[g]|=M<<P&67108863,this.words[g+1]=M>>>26-P&67108863,P+=24,P>=26&&(P-=26,g++);return this._strip()};function u(v,o){var l=v.charCodeAt(o);if(l>=48&&l<=57)return l-48;if(l>=65&&l<=70)return l-55;if(l>=97&&l<=102)return l-87;t(!1,"Invalid character in "+v)}function d(v,o,l){var c=u(v,l);return l-1>=o&&(c|=u(v,l-1)<<4),c}i.prototype._parseHex=function(o,l,c){this.length=Math.ceil((o.length-l)/6),this.words=new Array(this.length);for(var m=0;m<this.length;m++)this.words[m]=0;var g=0,M=0,P;if(c==="be")for(m=o.length-1;m>=l;m-=2)P=d(o,l,m)<<g,this.words[M]|=P&67108863,g>=18?(g-=18,M+=1,this.words[M]|=P>>>26):g+=8;else{var _=o.length-l;for(m=_%2===0?l+1:l;m<o.length;m+=2)P=d(o,l,m)<<g,this.words[M]|=P&67108863,g>=18?(g-=18,M+=1,this.words[M]|=P>>>26):g+=8}this._strip()};function f(v,o,l,c){for(var m=0,g=0,M=Math.min(v.length,l),P=o;P<M;P++){var _=v.charCodeAt(P)-48;m*=c,_>=49?g=_-49+10:_>=17?g=_-17+10:g=_,t(_>=0&&g<c,"Invalid character"),m+=g}return m}i.prototype._parseBase=function(o,l,c){this.words=[0],this.length=1;for(var m=0,g=1;g<=67108863;g*=l)m++;m--,g=g/l|0;for(var M=o.length-c,P=M%m,_=Math.min(M,M-P)+c,a=0,b=c;b<_;b+=m)a=f(o,b,b+m,l),this.imuln(g),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a);if(P!==0){var R=1;for(a=f(o,b,o.length,l),b=0;b<P;b++)R*=l;this.imuln(R),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a)}this._strip()},i.prototype.copy=function(o){o.words=new Array(this.length);for(var l=0;l<this.length;l++)o.words[l]=this.words[l];o.length=this.length,o.negative=this.negative,o.red=this.red};function h(v,o){v.words=o.words,v.length=o.length,v.negative=o.negative,v.red=o.red}if(i.prototype._move=function(o){h(o,this)},i.prototype.clone=function(){var o=new i(null);return this.copy(o),o},i.prototype._expand=function(o){for(;this.length<o;)this.words[this.length++]=0;return this},i.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},i.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{i.prototype[Symbol.for("nodejs.util.inspect.custom")]=p}catch{i.prototype.inspect=p}else i.prototype.inspect=p;function p(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var w=["","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];i.prototype.toString=function(o,l){o=o||10,l=l|0||1;var c;if(o===16||o==="hex"){c="";for(var m=0,g=0,M=0;M<this.length;M++){var P=this.words[M],_=((P<<m|g)&16777215).toString(16);g=P>>>24-m&16777215,m+=2,m>=26&&(m-=26,M--),g!==0||M!==this.length-1?c=w[6-_.length]+_+c:c=_+c}for(g!==0&&(c=g.toString(16)+c);c.length%l!==0;)c="0"+c;return this.negative!==0&&(c="-"+c),c}if(o===(o|0)&&o>=2&&o<=36){var a=y[o],b=A[o];c="";var R=this.clone();for(R.negative=0;!R.isZero();){var N=R.modrn(b).toString(o);R=R.idivn(b),R.isZero()?c=N+c:c=w[a-N.length]+N+c}for(this.isZero()&&(c="0"+c);c.length%l!==0;)c="0"+c;return this.negative!==0&&(c="-"+c),c}t(!1,"Base should be between 2 and 36")},i.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},i.prototype.toJSON=function(){return this.toString(16,2)},s&&(i.prototype.toBuffer=function(o,l){return this.toArrayLike(s,o,l)}),i.prototype.toArray=function(o,l){return this.toArrayLike(Array,o,l)};var B=function(o,l){return o.allocUnsafe?o.allocUnsafe(l):new o(l)};i.prototype.toArrayLike=function(o,l,c){this._strip();var m=this.byteLength(),g=c||Math.max(1,m);t(m<=g,"byte array longer than desired length"),t(g>0,"Requested array length <= 0");var M=B(o,g),P=l==="le"?"LE":"BE";return this["_toArrayLike"+P](M,m),M},i.prototype._toArrayLikeLE=function(o,l){for(var c=0,m=0,g=0,M=0;g<this.length;g++){var P=this.words[g]<<M|m;o[c++]=P&255,c<o.length&&(o[c++]=P>>8&255),c<o.length&&(o[c++]=P>>16&255),M===6?(c<o.length&&(o[c++]=P>>24&255),m=0,M=0):(m=P>>>24,M+=2)}if(c<o.length)for(o[c++]=m;c<o.length;)o[c++]=0},i.prototype._toArrayLikeBE=function(o,l){for(var c=o.length-1,m=0,g=0,M=0;g<this.length;g++){var P=this.words[g]<<M|m;o[c--]=P&255,c>=0&&(o[c--]=P>>8&255),c>=0&&(o[c--]=P>>16&255),M===6?(c>=0&&(o[c--]=P>>24&255),m=0,M=0):(m=P>>>24,M+=2)}if(c>=0)for(o[c--]=m;c>=0;)o[c--]=0},Math.clz32?i.prototype._countBits=function(o){return 32-Math.clz32(o)}:i.prototype._countBits=function(o){var l=o,c=0;return l>=4096&&(c+=13,l>>>=13),l>=64&&(c+=7,l>>>=7),l>=8&&(c+=4,l>>>=4),l>=2&&(c+=2,l>>>=2),c+l},i.prototype._zeroBits=function(o){if(o===0)return 26;var l=o,c=0;return(l&8191)===0&&(c+=13,l>>>=13),(l&127)===0&&(c+=7,l>>>=7),(l&15)===0&&(c+=4,l>>>=4),(l&3)===0&&(c+=2,l>>>=2),(l&1)===0&&c++,c},i.prototype.bitLength=function(){var o=this.words[this.length-1],l=this._countBits(o);return(this.length-1)*26+l};function S(v){for(var o=new Array(v.bitLength()),l=0;l<o.length;l++){var c=l/26|0,m=l%26;o[l]=v.words[c]>>>m&1}return o}i.prototype.zeroBits=function(){if(this.isZero())return 0;for(var o=0,l=0;l<this.length;l++){var c=this._zeroBits(this.words[l]);if(o+=c,c!==26)break}return o},i.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},i.prototype.toTwos=function(o){return this.negative!==0?this.abs().inotn(o).iaddn(1):this.clone()},i.prototype.fromTwos=function(o){return this.testn(o-1)?this.notn(o).iaddn(1).ineg():this.clone()},i.prototype.isNeg=function(){return this.negative!==0},i.prototype.neg=function(){return this.clone().ineg()},i.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},i.prototype.iuor=function(o){for(;this.length<o.length;)this.words[this.length++]=0;for(var l=0;l<o.length;l++)this.words[l]=this.words[l]|o.words[l];return this._strip()},i.prototype.ior=function(o){return t((this.negative|o.negative)===0),this.iuor(o)},i.prototype.or=function(o){return this.length>o.length?this.clone().ior(o):o.clone().ior(this)},i.prototype.uor=function(o){return this.length>o.length?this.clone().iuor(o):o.clone().iuor(this)},i.prototype.iuand=function(o){var l;this.length>o.length?l=o:l=this;for(var c=0;c<l.length;c++)this.words[c]=this.words[c]&o.words[c];return this.length=l.length,this._strip()},i.prototype.iand=function(o){return t((this.negative|o.negative)===0),this.iuand(o)},i.prototype.and=function(o){return this.length>o.length?this.clone().iand(o):o.clone().iand(this)},i.prototype.uand=function(o){return this.length>o.length?this.clone().iuand(o):o.clone().iuand(this)},i.prototype.iuxor=function(o){var l,c;this.length>o.length?(l=this,c=o):(l=o,c=this);for(var m=0;m<c.length;m++)this.words[m]=l.words[m]^c.words[m];if(this!==l)for(;m<l.length;m++)this.words[m]=l.words[m];return this.length=l.length,this._strip()},i.prototype.ixor=function(o){return t((this.negative|o.negative)===0),this.iuxor(o)},i.prototype.xor=function(o){return this.length>o.length?this.clone().ixor(o):o.clone().ixor(this)},i.prototype.uxor=function(o){return this.length>o.length?this.clone().iuxor(o):o.clone().iuxor(this)},i.prototype.inotn=function(o){t(typeof o=="number"&&o>=0);var l=Math.ceil(o/26)|0,c=o%26;this._expand(l),c>0&&l--;for(var m=0;m<l;m++)this.words[m]=~this.words[m]&67108863;return c>0&&(this.words[m]=~this.words[m]&67108863>>26-c),this._strip()},i.prototype.notn=function(o){return this.clone().inotn(o)},i.prototype.setn=function(o,l){t(typeof o=="number"&&o>=0);var c=o/26|0,m=o%26;return this._expand(c+1),l?this.words[c]=this.words[c]|1<<m:this.words[c]=this.words[c]&~(1<<m),this._strip()},i.prototype.iadd=function(o){var l;if(this.negative!==0&&o.negative===0)return this.negative=0,l=this.isub(o),this.negative^=1,this._normSign();if(this.negative===0&&o.negative!==0)return o.negative=0,l=this.isub(o),o.negative=1,l._normSign();var c,m;this.length>o.length?(c=this,m=o):(c=o,m=this);for(var g=0,M=0;M<m.length;M++)l=(c.words[M]|0)+(m.words[M]|0)+g,this.words[M]=l&67108863,g=l>>>26;for(;g!==0&&M<c.length;M++)l=(c.words[M]|0)+g,this.words[M]=l&67108863,g=l>>>26;if(this.length=c.length,g!==0)this.words[this.length]=g,this.length++;else if(c!==this)for(;M<c.length;M++)this.words[M]=c.words[M];return this},i.prototype.add=function(o){var l;return o.negative!==0&&this.negative===0?(o.negative=0,l=this.sub(o),o.negative^=1,l):o.negative===0&&this.negative!==0?(this.negative=0,l=o.sub(this),this.negative=1,l):this.length>o.length?this.clone().iadd(o):o.clone().iadd(this)},i.prototype.isub=function(o){if(o.negative!==0){o.negative=0;var l=this.iadd(o);return o.negative=1,l._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(o),this.negative=1,this._normSign();var c=this.cmp(o);if(c===0)return this.negative=0,this.length=1,this.words[0]=0,this;var m,g;c>0?(m=this,g=o):(m=o,g=this);for(var M=0,P=0;P<g.length;P++)l=(m.words[P]|0)-(g.words[P]|0)+M,M=l>>26,this.words[P]=l&67108863;for(;M!==0&&P<m.length;P++)l=(m.words[P]|0)+M,M=l>>26,this.words[P]=l&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()},i.prototype.sub=function(o){return this.clone().isub(o)};function T(v,o,l){l.negative=o.negative^v.negative;var c=v.length+o.length|0;l.length=c,c=c-1|0;var m=v.words[0]|0,g=o.words[0]|0,M=m*g,P=M&67108863,_=M/67108864|0;l.words[0]=P;for(var a=1;a<c;a++){for(var b=_>>>26,R=_&67108863,N=Math.min(a,o.length-1),L=Math.max(0,a-v.length+1);L<=N;L++){var V=a-L|0;m=v.words[V]|0,g=o.words[L]|0,M=m*g+R,b+=M/67108864|0,R=M&67108863}l.words[a]=R|0,_=b|0}return _!==0?l.words[a]=_|0:l.length--,l._strip()}var x=function(o,l,c){var m=o.words,g=l.words,M=c.words,P=0,_,a,b,R=m[0]|0,N=R&8191,L=R>>>13,V=m[1]|0,tt=V&8191,ot=V>>>13,le=m[2]|0,st=le&8191,lt=le>>>13,ji=m[3]|0,dt=ji&8191,ft=ji>>>13,Wi=m[4]|0,ct=Wi&8191,ht=Wi>>>13,Ui=m[5]|0,pt=Ui&8191,mt=Ui>>>13,Zi=m[6]|0,_t=Zi&8191,gt=Zi>>>13,Hi=m[7]|0,bt=Hi&8191,wt=Hi>>>13,Qi=m[8]|0,vt=Qi&8191,yt=Qi>>>13,Ki=m[9]|0,Mt=Ki&8191,Pt=Ki>>>13,$i=g[0]|0,At=$i&8191,St=$i>>>13,zi=g[1]|0,Bt=zi&8191,Et=zi>>>13,Gi=g[2]|0,It=Gi&8191,Ot=Gi>>>13,Vi=g[3]|0,Ct=Vi&8191,Tt=Vi>>>13,Xi=g[4]|0,xt=Xi&8191,kt=Xi>>>13,Ji=g[5]|0,Rt=Ji&8191,Ft=Ji>>>13,Yi=g[6]|0,Dt=Yi&8191,Nt=Yi>>>13,tr=g[7]|0,qt=tr&8191,Lt=tr>>>13,er=g[8]|0,jt=er&8191,Wt=er>>>13,ir=g[9]|0,Ut=ir&8191,Zt=ir>>>13;c.negative=o.negative^l.negative,c.length=19,_=Math.imul(N,At),a=Math.imul(N,St),a=a+Math.imul(L,At)|0,b=Math.imul(L,St);var Ye=(P+_|0)+((a&8191)<<13)|0;P=(b+(a>>>13)|0)+(Ye>>>26)|0,Ye&=67108863,_=Math.imul(tt,At),a=Math.imul(tt,St),a=a+Math.imul(ot,At)|0,b=Math.imul(ot,St),_=_+Math.imul(N,Bt)|0,a=a+Math.imul(N,Et)|0,a=a+Math.imul(L,Bt)|0,b=b+Math.imul(L,Et)|0;var ti=(P+_|0)+((a&8191)<<13)|0;P=(b+(a>>>13)|0)+(ti>>>26)|0,ti&=67108863,_=Math.imul(st,At),a=Math.imul(st,St),a=a+Math.imul(lt,At)|0,b=Math.imul(lt,St),_=_+Math.imul(tt,Bt)|0,a=a+Math.imul(tt,Et)|0,a=a+Math.imul(ot,Bt)|0,b=b+Math.imul(ot,Et)|0,_=_+Math.imul(N,It)|0,a=a+Math.imul(N,Ot)|0,a=a+Math.imul(L,It)|0,b=b+Math.imul(L,Ot)|0;var ei=(P+_|0)+((a&8191)<<13)|0;P=(b+(a>>>13)|0)+(ei>>>26)|0,ei&=67108863,_=Math.imul(dt,At),a=Math.imul(dt,St),a=a+Math.imul(ft,At)|0,b=Math.imul(ft,St),_=_+Math.imul(st,Bt)|0,a=a+Math.imul(st,Et)|0,a=a+Math.imul(lt,Bt)|0,b=b+Math.imul(lt,Et)|0,_=_+Math.imul(tt,It)|0,a=a+Math.imul(tt,Ot)|0,a=a+Math.imul(ot,It)|0,b=b+Math.imul(ot,Ot)|0,_=_+Math.imul(N,Ct)|0,a=a+Math.imul(N,Tt)|0,a=a+Math.imul(L,Ct)|0,b=b+Math.imul(L,Tt)|0;var ii=(P+_|0)+((a&8191)<<13)|0;P=(b+(a>>>13)|0)+(ii>>>26)|0,ii&=67108863,_=Math.imul(ct,At),a=Math.imul(ct,St),a=a+Math.imul(ht,At)|0,b=Math.imul(ht,St),_=_+Math.imul(dt,Bt)|0,a=a+Math.imul(dt,Et)|0,a=a+Math.imul(ft,Bt)|0,b=b+Math.imul(ft,Et)|0,_=_+Math.imul(st,It)|0,a=a+Math.imul(st,Ot)|0,a=a+Math.imul(lt,It)|0,b=b+Math.imul(lt,Ot)|0,_=_+Math.imul(tt,Ct)|0,a=a+Math.imul(tt,Tt)|0,a=a+Math.imul(ot,Ct)|0,b=b+Math.imul(ot,Tt)|0,_=_+Math.imul(N,xt)|0,a=a+Math.imul(N,kt)|0,a=a+Math.imul(L,xt)|0,b=b+Math.imul(L,kt)|0;var ri=(P+_|0)+((a&8191)<<13)|0;P=(b+(a>>>13)|0)+(ri>>>26)|0,ri&=67108863,_=Math.imul(pt,At),a=Math.imul(pt,St),a=a+Math.imul(mt,At)|0,b=Math.imul(mt,St),_=_+Math.imul(ct,Bt)|0,a=a+Math.imul(ct,Et)|0,a=a+Math.imul(ht,Bt)|0,b=b+Math.imul(ht,Et)|0,_=_+Math.imul(dt,It)|0,a=a+Math.imul(dt,Ot)|0,a=a+Math.imul(ft,It)|0,b=b+Math.imul(ft,Ot)|0,_=_+Math.imul(st,Ct)|0,a=a+Math.imul(st,Tt)|0,a=a+Math.imul(lt,Ct)|0,b=b+Math.imul(lt,Tt)|0,_=_+Math.imul(tt,xt)|0,a=a+Math.imul(tt,kt)|0,a=a+Math.imul(ot,xt)|0,b=b+Math.imul(ot,kt)|0,_=_+Math.imul(N,Rt)|0,a=a+Math.imul(N,Ft)|0,a=a+Math.imul(L,Rt)|0,b=b+Math.imul(L,Ft)|0;var ni=(P+_|0)+((a&8191)<<13)|0;P=(b+(a>>>13)|0)+(ni>>>26)|0,ni&=67108863,_=Math.imul(_t,At),a=Math.imul(_t,St),a=a+Math.imul(gt,At)|0,b=Math.imul(gt,St),_=_+Math.imul(pt,Bt)|0,a=a+Math.imul(pt,Et)|0,a=a+Math.imul(mt,Bt)|0,b=b+Math.imul(mt,Et)|0,_=_+Math.imul(ct,It)|0,a=a+Math.imul(ct,Ot)|0,a=a+Math.imul(ht,It)|0,b=b+Math.imul(ht,Ot)|0,_=_+Math.imul(dt,Ct)|0,a=a+Math.imul(dt,Tt)|0,a=a+Math.imul(ft,Ct)|0,b=b+Math.imul(ft,Tt)|0,_=_+Math.imul(st,xt)|0,a=a+Math.imul(st,kt)|0,a=a+Math.imul(lt,xt)|0,b=b+Math.imul(lt,kt)|0,_=_+Math.imul(tt,Rt)|0,a=a+Math.imul(tt,Ft)|0,a=a+Math.imul(ot,Rt)|0,b=b+Math.imul(ot,Ft)|0,_=_+Math.imul(N,Dt)|0,a=a+Math.imul(N,Nt)|0,a=a+Math.imul(L,Dt)|0,b=b+Math.imul(L,Nt)|0;var oi=(P+_|0)+((a&8191)<<13)|0;P=(b+(a>>>13)|0)+(oi>>>26)|0,oi&=67108863,_=Math.imul(bt,At),a=Math.imul(bt,St),a=a+Math.imul(wt,At)|0,b=Math.imul(wt,St),_=_+Math.imul(_t,Bt)|0,a=a+Math.imul(_t,Et)|0,a=a+Math.imul(gt,Bt)|0,b=b+Math.imul(gt,Et)|0,_=_+Math.imul(pt,It)|0,a=a+Math.imul(pt,Ot)|0,a=a+Math.imul(mt,It)|0,b=b+Math.imul(mt,Ot)|0,_=_+Math.imul(ct,Ct)|0,a=a+Math.imul(ct,Tt)|0,a=a+Math.imul(ht,Ct)|0,b=b+Math.imul(ht,Tt)|0,_=_+Math.imul(dt,xt)|0,a=a+Math.imul(dt,kt)|0,a=a+Math.imul(ft,xt)|0,b=b+Math.imul(ft,kt)|0,_=_+Math.imul(st,Rt)|0,a=a+Math.imul(st,Ft)|0,a=a+Math.imul(lt,Rt)|0,b=b+Math.imul(lt,Ft)|0,_=_+Math.imul(tt,Dt)|0,a=a+Math.imul(tt,Nt)|0,a=a+Math.imul(ot,Dt)|0,b=b+Math.imul(ot,Nt)|0,_=_+Math.imul(N,qt)|0,a=a+Math.imul(N,Lt)|0,a=a+Math.imul(L,qt)|0,b=b+Math.imul(L,Lt)|0;var si=(P+_|0)+((a&8191)<<13)|0;P=(b+(a>>>13)|0)+(si>>>26)|0,si&=67108863,_=Math.imul(vt,At),a=Math.imul(vt,St),a=a+Math.imul(yt,At)|0,b=Math.imul(yt,St),_=_+Math.imul(bt,Bt)|0,a=a+Math.imul(bt,Et)|0,a=a+Math.imul(wt,Bt)|0,b=b+Math.imul(wt,Et)|0,_=_+Math.imul(_t,It)|0,a=a+Math.imul(_t,Ot)|0,a=a+Math.imul(gt,It)|0,b=b+Math.imul(gt,Ot)|0,_=_+Math.imul(pt,Ct)|0,a=a+Math.imul(pt,Tt)|0,a=a+Math.imul(mt,Ct)|0,b=b+Math.imul(mt,Tt)|0,_=_+Math.imul(ct,xt)|0,a=a+Math.imul(ct,kt)|0,a=a+Math.imul(ht,xt)|0,b=b+Math.imul(ht,kt)|0,_=_+Math.imul(dt,Rt)|0,a=a+Math.imul(dt,Ft)|0,a=a+Math.imul(ft,Rt)|0,b=b+Math.imul(ft,Ft)|0,_=_+Math.imul(st,Dt)|0,a=a+Math.imul(st,Nt)|0,a=a+Math.imul(lt,Dt)|0,b=b+Math.imul(lt,Nt)|0,_=_+Math.imul(tt,qt)|0,a=a+Math.imul(tt,Lt)|0,a=a+Math.imul(ot,qt)|0,b=b+Math.imul(ot,Lt)|0,_=_+Math.imul(N,jt)|0,a=a+Math.imul(N,Wt)|0,a=a+Math.imul(L,jt)|0,b=b+Math.imul(L,Wt)|0;var ai=(P+_|0)+((a&8191)<<13)|0;P=(b+(a>>>13)|0)+(ai>>>26)|0,ai&=67108863,_=Math.imul(Mt,At),a=Math.imul(Mt,St),a=a+Math.imul(Pt,At)|0,b=Math.imul(Pt,St),_=_+Math.imul(vt,Bt)|0,a=a+Math.imul(vt,Et)|0,a=a+Math.imul(yt,Bt)|0,b=b+Math.imul(yt,Et)|0,_=_+Math.imul(bt,It)|0,a=a+Math.imul(bt,Ot)|0,a=a+Math.imul(wt,It)|0,b=b+Math.imul(wt,Ot)|0,_=_+Math.imul(_t,Ct)|0,a=a+Math.imul(_t,Tt)|0,a=a+Math.imul(gt,Ct)|0,b=b+Math.imul(gt,Tt)|0,_=_+Math.imul(pt,xt)|0,a=a+Math.imul(pt,kt)|0,a=a+Math.imul(mt,xt)|0,b=b+Math.imul(mt,kt)|0,_=_+Math.imul(ct,Rt)|0,a=a+Math.imul(ct,Ft)|0,a=a+Math.imul(ht,Rt)|0,b=b+Math.imul(ht,Ft)|0,_=_+Math.imul(dt,Dt)|0,a=a+Math.imul(dt,Nt)|0,a=a+Math.imul(ft,Dt)|0,b=b+Math.imul(ft,Nt)|0,_=_+Math.imul(st,qt)|0,a=a+Math.imul(st,Lt)|0,a=a+Math.imul(lt,qt)|0,b=b+Math.imul(lt,Lt)|0,_=_+Math.imul(tt,jt)|0,a=a+Math.imul(tt,Wt)|0,a=a+Math.imul(ot,jt)|0,b=b+Math.imul(ot,Wt)|0,_=_+Math.imul(N,Ut)|0,a=a+Math.imul(N,Zt)|0,a=a+Math.imul(L,Ut)|0,b=b+Math.imul(L,Zt)|0;var li=(P+_|0)+((a&8191)<<13)|0;P=(b+(a>>>13)|0)+(li>>>26)|0,li&=67108863,_=Math.imul(Mt,Bt),a=Math.imul(Mt,Et),a=a+Math.imul(Pt,Bt)|0,b=Math.imul(Pt,Et),_=_+Math.imul(vt,It)|0,a=a+Math.imul(vt,Ot)|0,a=a+Math.imul(yt,It)|0,b=b+Math.imul(yt,Ot)|0,_=_+Math.imul(bt,Ct)|0,a=a+Math.imul(bt,Tt)|0,a=a+Math.imul(wt,Ct)|0,b=b+Math.imul(wt,Tt)|0,_=_+Math.imul(_t,xt)|0,a=a+Math.imul(_t,kt)|0,a=a+Math.imul(gt,xt)|0,b=b+Math.imul(gt,kt)|0,_=_+Math.imul(pt,Rt)|0,a=a+Math.imul(pt,Ft)|0,a=a+Math.imul(mt,Rt)|0,b=b+Math.imul(mt,Ft)|0,_=_+Math.imul(ct,Dt)|0,a=a+Math.imul(ct,Nt)|0,a=a+Math.imul(ht,Dt)|0,b=b+Math.imul(ht,Nt)|0,_=_+Math.imul(dt,qt)|0,a=a+Math.imul(dt,Lt)|0,a=a+Math.imul(ft,qt)|0,b=b+Math.imul(ft,Lt)|0,_=_+Math.imul(st,jt)|0,a=a+Math.imul(st,Wt)|0,a=a+Math.imul(lt,jt)|0,b=b+Math.imul(lt,Wt)|0,_=_+Math.imul(tt,Ut)|0,a=a+Math.imul(tt,Zt)|0,a=a+Math.imul(ot,Ut)|0,b=b+Math.imul(ot,Zt)|0;var ui=(P+_|0)+((a&8191)<<13)|0;P=(b+(a>>>13)|0)+(ui>>>26)|0,ui&=67108863,_=Math.imul(Mt,It),a=Math.imul(Mt,Ot),a=a+Math.imul(Pt,It)|0,b=Math.imul(Pt,Ot),_=_+Math.imul(vt,Ct)|0,a=a+Math.imul(vt,Tt)|0,a=a+Math.imul(yt,Ct)|0,b=b+Math.imul(yt,Tt)|0,_=_+Math.imul(bt,xt)|0,a=a+Math.imul(bt,kt)|0,a=a+Math.imul(wt,xt)|0,b=b+Math.imul(wt,kt)|0,_=_+Math.imul(_t,Rt)|0,a=a+Math.imul(_t,Ft)|0,a=a+Math.imul(gt,Rt)|0,b=b+Math.imul(gt,Ft)|0,_=_+Math.imul(pt,Dt)|0,a=a+Math.imul(pt,Nt)|0,a=a+Math.imul(mt,Dt)|0,b=b+Math.imul(mt,Nt)|0,_=_+Math.imul(ct,qt)|0,a=a+Math.imul(ct,Lt)|0,a=a+Math.imul(ht,qt)|0,b=b+Math.imul(ht,Lt)|0,_=_+Math.imul(dt,jt)|0,a=a+Math.imul(dt,Wt)|0,a=a+Math.imul(ft,jt)|0,b=b+Math.imul(ft,Wt)|0,_=_+Math.imul(st,Ut)|0,a=a+Math.imul(st,Zt)|0,a=a+Math.imul(lt,Ut)|0,b=b+Math.imul(lt,Zt)|0;var di=(P+_|0)+((a&8191)<<13)|0;P=(b+(a>>>13)|0)+(di>>>26)|0,di&=67108863,_=Math.imul(Mt,Ct),a=Math.imul(Mt,Tt),a=a+Math.imul(Pt,Ct)|0,b=Math.imul(Pt,Tt),_=_+Math.imul(vt,xt)|0,a=a+Math.imul(vt,kt)|0,a=a+Math.imul(yt,xt)|0,b=b+Math.imul(yt,kt)|0,_=_+Math.imul(bt,Rt)|0,a=a+Math.imul(bt,Ft)|0,a=a+Math.imul(wt,Rt)|0,b=b+Math.imul(wt,Ft)|0,_=_+Math.imul(_t,Dt)|0,a=a+Math.imul(_t,Nt)|0,a=a+Math.imul(gt,Dt)|0,b=b+Math.imul(gt,Nt)|0,_=_+Math.imul(pt,qt)|0,a=a+Math.imul(pt,Lt)|0,a=a+Math.imul(mt,qt)|0,b=b+Math.imul(mt,Lt)|0,_=_+Math.imul(ct,jt)|0,a=a+Math.imul(ct,Wt)|0,a=a+Math.imul(ht,jt)|0,b=b+Math.imul(ht,Wt)|0,_=_+Math.imul(dt,Ut)|0,a=a+Math.imul(dt,Zt)|0,a=a+Math.imul(ft,Ut)|0,b=b+Math.imul(ft,Zt)|0;var fi=(P+_|0)+((a&8191)<<13)|0;P=(b+(a>>>13)|0)+(fi>>>26)|0,fi&=67108863,_=Math.imul(Mt,xt),a=Math.imul(Mt,kt),a=a+Math.imul(Pt,xt)|0,b=Math.imul(Pt,kt),_=_+Math.imul(vt,Rt)|0,a=a+Math.imul(vt,Ft)|0,a=a+Math.imul(yt,Rt)|0,b=b+Math.imul(yt,Ft)|0,_=_+Math.imul(bt,Dt)|0,a=a+Math.imul(bt,Nt)|0,a=a+Math.imul(wt,Dt)|0,b=b+Math.imul(wt,Nt)|0,_=_+Math.imul(_t,qt)|0,a=a+Math.imul(_t,Lt)|0,a=a+Math.imul(gt,qt)|0,b=b+Math.imul(gt,Lt)|0,_=_+Math.imul(pt,jt)|0,a=a+Math.imul(pt,Wt)|0,a=a+Math.imul(mt,jt)|0,b=b+Math.imul(mt,Wt)|0,_=_+Math.imul(ct,Ut)|0,a=a+Math.imul(ct,Zt)|0,a=a+Math.imul(ht,Ut)|0,b=b+Math.imul(ht,Zt)|0;var ci=(P+_|0)+((a&8191)<<13)|0;P=(b+(a>>>13)|0)+(ci>>>26)|0,ci&=67108863,_=Math.imul(Mt,Rt),a=Math.imul(Mt,Ft),a=a+Math.imul(Pt,Rt)|0,b=Math.imul(Pt,Ft),_=_+Math.imul(vt,Dt)|0,a=a+Math.imul(vt,Nt)|0,a=a+Math.imul(yt,Dt)|0,b=b+Math.imul(yt,Nt)|0,_=_+Math.imul(bt,qt)|0,a=a+Math.imul(bt,Lt)|0,a=a+Math.imul(wt,qt)|0,b=b+Math.imul(wt,Lt)|0,_=_+Math.imul(_t,jt)|0,a=a+Math.imul(_t,Wt)|0,a=a+Math.imul(gt,jt)|0,b=b+Math.imul(gt,Wt)|0,_=_+Math.imul(pt,Ut)|0,a=a+Math.imul(pt,Zt)|0,a=a+Math.imul(mt,Ut)|0,b=b+Math.imul(mt,Zt)|0;var hi=(P+_|0)+((a&8191)<<13)|0;P=(b+(a>>>13)|0)+(hi>>>26)|0,hi&=67108863,_=Math.imul(Mt,Dt),a=Math.imul(Mt,Nt),a=a+Math.imul(Pt,Dt)|0,b=Math.imul(Pt,Nt),_=_+Math.imul(vt,qt)|0,a=a+Math.imul(vt,Lt)|0,a=a+Math.imul(yt,qt)|0,b=b+Math.imul(yt,Lt)|0,_=_+Math.imul(bt,jt)|0,a=a+Math.imul(bt,Wt)|0,a=a+Math.imul(wt,jt)|0,b=b+Math.imul(wt,Wt)|0,_=_+Math.imul(_t,Ut)|0,a=a+Math.imul(_t,Zt)|0,a=a+Math.imul(gt,Ut)|0,b=b+Math.imul(gt,Zt)|0;var pi=(P+_|0)+((a&8191)<<13)|0;P=(b+(a>>>13)|0)+(pi>>>26)|0,pi&=67108863,_=Math.imul(Mt,qt),a=Math.imul(Mt,Lt),a=a+Math.imul(Pt,qt)|0,b=Math.imul(Pt,Lt),_=_+Math.imul(vt,jt)|0,a=a+Math.imul(vt,Wt)|0,a=a+Math.imul(yt,jt)|0,b=b+Math.imul(yt,Wt)|0,_=_+Math.imul(bt,Ut)|0,a=a+Math.imul(bt,Zt)|0,a=a+Math.imul(wt,Ut)|0,b=b+Math.imul(wt,Zt)|0;var mi=(P+_|0)+((a&8191)<<13)|0;P=(b+(a>>>13)|0)+(mi>>>26)|0,mi&=67108863,_=Math.imul(Mt,jt),a=Math.imul(Mt,Wt),a=a+Math.imul(Pt,jt)|0,b=Math.imul(Pt,Wt),_=_+Math.imul(vt,Ut)|0,a=a+Math.imul(vt,Zt)|0,a=a+Math.imul(yt,Ut)|0,b=b+Math.imul(yt,Zt)|0;var _i=(P+_|0)+((a&8191)<<13)|0;P=(b+(a>>>13)|0)+(_i>>>26)|0,_i&=67108863,_=Math.imul(Mt,Ut),a=Math.imul(Mt,Zt),a=a+Math.imul(Pt,Ut)|0,b=Math.imul(Pt,Zt);var gi=(P+_|0)+((a&8191)<<13)|0;return P=(b+(a>>>13)|0)+(gi>>>26)|0,gi&=67108863,M[0]=Ye,M[1]=ti,M[2]=ei,M[3]=ii,M[4]=ri,M[5]=ni,M[6]=oi,M[7]=si,M[8]=ai,M[9]=li,M[10]=ui,M[11]=di,M[12]=fi,M[13]=ci,M[14]=hi,M[15]=pi,M[16]=mi,M[17]=_i,M[18]=gi,P!==0&&(M[19]=P,c.length++),c};Math.imul||(x=T);function k(v,o,l){l.negative=o.negative^v.negative,l.length=v.length+o.length;for(var c=0,m=0,g=0;g<l.length-1;g++){var M=m;m=0;for(var P=c&67108863,_=Math.min(g,o.length-1),a=Math.max(0,g-v.length+1);a<=_;a++){var b=g-a,R=v.words[b]|0,N=o.words[a]|0,L=R*N,V=L&67108863;M=M+(L/67108864|0)|0,V=V+P|0,P=V&67108863,M=M+(V>>>26)|0,m+=M>>>26,M&=67108863}l.words[g]=P,c=M,M=m}return c!==0?l.words[g]=c:l.length--,l._strip()}function I(v,o,l){return k(v,o,l)}i.prototype.mulTo=function(o,l){var c,m=this.length+o.length;return this.length===10&&o.length===10?c=x(this,o,l):m<63?c=T(this,o,l):m<1024?c=k(this,o,l):c=I(this,o,l),c};function C(v,o){this.x=v,this.y=o}C.prototype.makeRBT=function(o){for(var l=new Array(o),c=i.prototype._countBits(o)-1,m=0;m<o;m++)l[m]=this.revBin(m,c,o);return l},C.prototype.revBin=function(o,l,c){if(o===0||o===c-1)return o;for(var m=0,g=0;g<l;g++)m|=(o&1)<<l-g-1,o>>=1;return m},C.prototype.permute=function(o,l,c,m,g,M){for(var P=0;P<M;P++)m[P]=l[o[P]],g[P]=c[o[P]]},C.prototype.transform=function(o,l,c,m,g,M){this.permute(M,o,l,c,m,g);for(var P=1;P<g;P<<=1)for(var _=P<<1,a=Math.cos(2*Math.PI/_),b=Math.sin(2*Math.PI/_),R=0;R<g;R+=_)for(var N=a,L=b,V=0;V<P;V++){var tt=c[R+V],ot=m[R+V],le=c[R+V+P],st=m[R+V+P],lt=N*le-L*st;st=N*st+L*le,le=lt,c[R+V]=tt+le,m[R+V]=ot+st,c[R+V+P]=tt-le,m[R+V+P]=ot-st,V!==_&&(lt=a*N-b*L,L=a*L+b*N,N=lt)}},C.prototype.guessLen13b=function(o,l){var c=Math.max(l,o)|1,m=c&1,g=0;for(c=c/2|0;c;c=c>>>1)g++;return 1<<g+1+m},C.prototype.conjugate=function(o,l,c){if(!(c<=1))for(var m=0;m<c/2;m++){var g=o[m];o[m]=o[c-m-1],o[c-m-1]=g,g=l[m],l[m]=-l[c-m-1],l[c-m-1]=-g}},C.prototype.normalize13b=function(o,l){for(var c=0,m=0;m<l/2;m++){var g=Math.round(o[2*m+1]/l)*8192+Math.round(o[2*m]/l)+c;o[m]=g&67108863,g<67108864?c=0:c=g/67108864|0}return o},C.prototype.convert13b=function(o,l,c,m){for(var g=0,M=0;M<l;M++)g=g+(o[M]|0),c[2*M]=g&8191,g=g>>>13,c[2*M+1]=g&8191,g=g>>>13;for(M=2*l;M<m;++M)c[M]=0;t(g===0),t((g&-8192)===0)},C.prototype.stub=function(o){for(var l=new Array(o),c=0;c<o;c++)l[c]=0;return l},C.prototype.mulp=function(o,l,c){var m=2*this.guessLen13b(o.length,l.length),g=this.makeRBT(m),M=this.stub(m),P=new Array(m),_=new Array(m),a=new Array(m),b=new Array(m),R=new Array(m),N=new Array(m),L=c.words;L.length=m,this.convert13b(o.words,o.length,P,m),this.convert13b(l.words,l.length,b,m),this.transform(P,M,_,a,m,g),this.transform(b,M,R,N,m,g);for(var V=0;V<m;V++){var tt=_[V]*R[V]-a[V]*N[V];a[V]=_[V]*N[V]+a[V]*R[V],_[V]=tt}return this.conjugate(_,a,m),this.transform(_,a,L,M,m,g),this.conjugate(L,M,m),this.normalize13b(L,m),c.negative=o.negative^l.negative,c.length=o.length+l.length,c._strip()},i.prototype.mul=function(o){var l=new i(null);return l.words=new Array(this.length+o.length),this.mulTo(o,l)},i.prototype.mulf=function(o){var l=new i(null);return l.words=new Array(this.length+o.length),I(this,o,l)},i.prototype.imul=function(o){return this.clone().mulTo(o,this)},i.prototype.imuln=function(o){var l=o<0;l&&(o=-o),t(typeof o=="number"),t(o<67108864);for(var c=0,m=0;m<this.length;m++){var g=(this.words[m]|0)*o,M=(g&67108863)+(c&67108863);c>>=26,c+=g/67108864|0,c+=M>>>26,this.words[m]=M&67108863}return c!==0&&(this.words[m]=c,this.length++),this.length=o===0?1:this.length,l?this.ineg():this},i.prototype.muln=function(o){return this.clone().imuln(o)},i.prototype.sqr=function(){return this.mul(this)},i.prototype.isqr=function(){return this.imul(this.clone())},i.prototype.pow=function(o){var l=S(o);if(l.length===0)return new i(1);for(var c=this,m=0;m<l.length&&l[m]===0;m++,c=c.sqr());if(++m<l.length)for(var g=c.sqr();m<l.length;m++,g=g.sqr())l[m]!==0&&(c=c.mul(g));return c},i.prototype.iushln=function(o){t(typeof o=="number"&&o>=0);var l=o%26,c=(o-l)/26,m=67108863>>>26-l<<26-l,g;if(l!==0){var M=0;for(g=0;g<this.length;g++){var P=this.words[g]&m,_=(this.words[g]|0)-P<<l;this.words[g]=_|M,M=P>>>26-l}M&&(this.words[g]=M,this.length++)}if(c!==0){for(g=this.length-1;g>=0;g--)this.words[g+c]=this.words[g];for(g=0;g<c;g++)this.words[g]=0;this.length+=c}return this._strip()},i.prototype.ishln=function(o){return t(this.negative===0),this.iushln(o)},i.prototype.iushrn=function(o,l,c){t(typeof o=="number"&&o>=0);var m;l?m=(l-l%26)/26:m=0;var g=o%26,M=Math.min((o-g)/26,this.length),P=67108863^67108863>>>g<<g,_=c;if(m-=M,m=Math.max(0,m),_){for(var a=0;a<M;a++)_.words[a]=this.words[a];_.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 b=0;for(a=this.length-1;a>=0&&(b!==0||a>=m);a--){var R=this.words[a]|0;this.words[a]=b<<26-g|R>>>g,b=R&P}return _&&b!==0&&(_.words[_.length++]=b),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},i.prototype.ishrn=function(o,l,c){return t(this.negative===0),this.iushrn(o,l,c)},i.prototype.shln=function(o){return this.clone().ishln(o)},i.prototype.ushln=function(o){return this.clone().iushln(o)},i.prototype.shrn=function(o){return this.clone().ishrn(o)},i.prototype.ushrn=function(o){return this.clone().iushrn(o)},i.prototype.testn=function(o){t(typeof o=="number"&&o>=0);var l=o%26,c=(o-l)/26,m=1<<l;if(this.length<=c)return!1;var g=this.words[c];return!!(g&m)},i.prototype.imaskn=function(o){t(typeof o=="number"&&o>=0);var l=o%26,c=(o-l)/26;if(t(this.negative===0,"imaskn works only with positive numbers"),this.length<=c)return this;if(l!==0&&c++,this.length=Math.min(c,this.length),l!==0){var m=67108863^67108863>>>l<<l;this.words[this.length-1]&=m}return this._strip()},i.prototype.maskn=function(o){return this.clone().imaskn(o)},i.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)},i.prototype._iaddn=function(o){this.words[0]+=o;for(var l=0;l<this.length&&this.words[l]>=67108864;l++)this.words[l]-=67108864,l===this.length-1?this.words[l+1]=1:this.words[l+1]++;return this.length=Math.max(this.length,l+1),this},i.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 l=0;l<this.length&&this.words[l]<0;l++)this.words[l]+=67108864,this.words[l+1]-=1;return this._strip()},i.prototype.addn=function(o){return this.clone().iaddn(o)},i.prototype.subn=function(o){return this.clone().isubn(o)},i.prototype.iabs=function(){return this.negative=0,this},i.prototype.abs=function(){return this.clone().iabs()},i.prototype._ishlnsubmul=function(o,l,c){var m=o.length+c,g;this._expand(m);var M,P=0;for(g=0;g<o.length;g++){M=(this.words[g+c]|0)+P;var _=(o.words[g]|0)*l;M-=_&67108863,P=(M>>26)-(_/67108864|0),this.words[g+c]=M&67108863}for(;g<this.length-c;g++)M=(this.words[g+c]|0)+P,P=M>>26,this.words[g+c]=M&67108863;if(P===0)return this._strip();for(t(P===-1),P=0,g=0;g<this.length;g++)M=-(this.words[g]|0)+P,P=M>>26,this.words[g]=M&67108863;return this.negative=1,this._strip()},i.prototype._wordDiv=function(o,l){var c=this.length-o.length,m=this.clone(),g=o,M=g.words[g.length-1]|0,P=this._countBits(M);c=26-P,c!==0&&(g=g.ushln(c),m.iushln(c),M=g.words[g.length-1]|0);var _=m.length-g.length,a;if(l!=="mod"){a=new i(null),a.length=_+1,a.words=new Array(a.length);for(var b=0;b<a.length;b++)a.words[b]=0}var R=m.clone()._ishlnsubmul(g,1,_);R.negative===0&&(m=R,a&&(a.words[_]=1));for(var N=_-1;N>=0;N--){var L=(m.words[g.length+N]|0)*67108864+(m.words[g.length+N-1]|0);for(L=Math.min(L/M|0,67108863),m._ishlnsubmul(g,L,N);m.negative!==0;)L--,m.negative=0,m._ishlnsubmul(g,1,N),m.isZero()||(m.negative^=1);a&&(a.words[N]=L)}return a&&a._strip(),m._strip(),l!=="div"&&c!==0&&m.iushrn(c),{div:a||null,mod:m}},i.prototype.divmod=function(o,l,c){if(t(!o.isZero()),this.isZero())return{div:new i(0),mod:new i(0)};var m,g,M;return this.negative!==0&&o.negative===0?(M=this.neg().divmod(o,l),l!=="mod"&&(m=M.div.neg()),l!=="div"&&(g=M.mod.neg(),c&&g.negative!==0&&g.iadd(o)),{div:m,mod:g}):this.negative===0&&o.negative!==0?(M=this.divmod(o.neg(),l),l!=="mod"&&(m=M.div.neg()),{div:m,mod:M.mod}):(this.negative&o.negative)!==0?(M=this.neg().divmod(o.neg(),l),l!=="div"&&(g=M.mod.neg(),c&&g.negative!==0&&g.isub(o)),{div:M.div,mod:g}):o.length>this.length||this.cmp(o)<0?{div:new i(0),mod:this}:o.length===1?l==="div"?{div:this.divn(o.words[0]),mod:null}:l==="mod"?{div:null,mod:new i(this.modrn(o.words[0]))}:{div:this.divn(o.words[0]),mod:new i(this.modrn(o.words[0]))}:this._wordDiv(o,l)},i.prototype.div=function(o){return this.divmod(o,"div",!1).div},i.prototype.mod=function(o){return this.divmod(o,"mod",!1).mod},i.prototype.umod=function(o){return this.divmod(o,"mod",!0).mod},i.prototype.divRound=function(o){var l=this.divmod(o);if(l.mod.isZero())return l.div;var c=l.div.negative!==0?l.mod.isub(o):l.mod,m=o.ushrn(1),g=o.andln(1),M=c.cmp(m);return M<0||g===1&&M===0?l.div:l.div.negative!==0?l.div.isubn(1):l.div.iaddn(1)},i.prototype.modrn=function(o){var l=o<0;l&&(o=-o),t(o<=67108863);for(var c=(1<<26)%o,m=0,g=this.length-1;g>=0;g--)m=(c*m+(this.words[g]|0))%o;return l?-m:m},i.prototype.modn=function(o){return this.modrn(o)},i.prototype.idivn=function(o){var l=o<0;l&&(o=-o),t(o<=67108863);for(var c=0,m=this.length-1;m>=0;m--){var g=(this.words[m]|0)+c*67108864;this.words[m]=g/o|0,c=g%o}return this._strip(),l?this.ineg():this},i.prototype.divn=function(o){return this.clone().idivn(o)},i.prototype.egcd=function(o){t(o.negative===0),t(!o.isZero());var l=this,c=o.clone();l.negative!==0?l=l.umod(o):l=l.clone();for(var m=new i(1),g=new i(0),M=new i(0),P=new i(1),_=0;l.isEven()&&c.isEven();)l.iushrn(1),c.iushrn(1),++_;for(var a=c.clone(),b=l.clone();!l.isZero();){for(var R=0,N=1;(l.words[0]&N)===0&&R<26;++R,N<<=1);if(R>0)for(l.iushrn(R);R-- >0;)(m.isOdd()||g.isOdd())&&(m.iadd(a),g.isub(b)),m.iushrn(1),g.iushrn(1);for(var L=0,V=1;(c.words[0]&V)===0&&L<26;++L,V<<=1);if(L>0)for(c.iushrn(L);L-- >0;)(M.isOdd()||P.isOdd())&&(M.iadd(a),P.isub(b)),M.iushrn(1),P.iushrn(1);l.cmp(c)>=0?(l.isub(c),m.isub(M),g.isub(P)):(c.isub(l),M.isub(m),P.isub(g))}return{a:M,b:P,gcd:c.iushln(_)}},i.prototype._invmp=function(o){t(o.negative===0),t(!o.isZero());var l=this,c=o.clone();l.negative!==0?l=l.umod(o):l=l.clone();for(var m=new i(1),g=new i(0),M=c.clone();l.cmpn(1)>0&&c.cmpn(1)>0;){for(var P=0,_=1;(l.words[0]&_)===0&&P<26;++P,_<<=1);if(P>0)for(l.iushrn(P);P-- >0;)m.isOdd()&&m.iadd(M),m.iushrn(1);for(var a=0,b=1;(c.words[0]&b)===0&&a<26;++a,b<<=1);if(a>0)for(c.iushrn(a);a-- >0;)g.isOdd()&&g.iadd(M),g.iushrn(1);l.cmp(c)>=0?(l.isub(c),m.isub(g)):(c.isub(l),g.isub(m))}var R;return l.cmpn(1)===0?R=m:R=g,R.cmpn(0)<0&&R.iadd(o),R},i.prototype.gcd=function(o){if(this.isZero())return o.abs();if(o.isZero())return this.abs();var l=this.clone(),c=o.clone();l.negative=0,c.negative=0;for(var m=0;l.isEven()&&c.isEven();m++)l.iushrn(1),c.iushrn(1);do{for(;l.isEven();)l.iushrn(1);for(;c.isEven();)c.iushrn(1);var g=l.cmp(c);if(g<0){var M=l;l=c,c=M}else if(g===0||c.cmpn(1)===0)break;l.isub(c)}while(!0);return c.iushln(m)},i.prototype.invm=function(o){return this.egcd(o).a.umod(o)},i.prototype.isEven=function(){return(this.words[0]&1)===0},i.prototype.isOdd=function(){return(this.words[0]&1)===1},i.prototype.andln=function(o){return this.words[0]&o},i.prototype.bincn=function(o){t(typeof o=="number");var l=o%26,c=(o-l)/26,m=1<<l;if(this.length<=c)return this._expand(c+1),this.words[c]|=m,this;for(var g=m,M=c;g!==0&&M<this.length;M++){var P=this.words[M]|0;P+=g,g=P>>>26,P&=67108863,this.words[M]=P}return g!==0&&(this.words[M]=g,this.length++),this},i.prototype.isZero=function(){return this.length===1&&this.words[0]===0},i.prototype.cmpn=function(o){var l=o<0;if(this.negative!==0&&!l)return-1;if(this.negative===0&&l)return 1;this._strip();var c;if(this.length>1)c=1;else{l&&(o=-o),t(o<=67108863,"Number is too big");var m=this.words[0]|0;c=m===o?0:m<o?-1:1}return this.negative!==0?-c|0:c},i.prototype.cmp=function(o){if(this.negative!==0&&o.negative===0)return-1;if(this.negative===0&&o.negative!==0)return 1;var l=this.ucmp(o);return this.negative!==0?-l|0:l},i.prototype.ucmp=function(o){if(this.length>o.length)return 1;if(this.length<o.length)return-1;for(var l=0,c=this.length-1;c>=0;c--){var m=this.words[c]|0,g=o.words[c]|0;if(m!==g){m<g?l=-1:m>g&&(l=1);break}}return l},i.prototype.gtn=function(o){return this.cmpn(o)===1},i.prototype.gt=function(o){return this.cmp(o)===1},i.prototype.gten=function(o){return this.cmpn(o)>=0},i.prototype.gte=function(o){return this.cmp(o)>=0},i.prototype.ltn=function(o){return this.cmpn(o)===-1},i.prototype.lt=function(o){return this.cmp(o)===-1},i.prototype.lten=function(o){return this.cmpn(o)<=0},i.prototype.lte=function(o){return this.cmp(o)<=0},i.prototype.eqn=function(o){return this.cmpn(o)===0},i.prototype.eq=function(o){return this.cmp(o)===0},i.red=function(o){return new H(o)},i.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)},i.prototype.fromRed=function(){return t(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},i.prototype._forceRed=function(o){return this.red=o,this},i.prototype.forceRed=function(o){return t(!this.red,"Already a number in reduction context"),this._forceRed(o)},i.prototype.redAdd=function(o){return t(this.red,"redAdd works only with red numbers"),this.red.add(this,o)},i.prototype.redIAdd=function(o){return t(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,o)},i.prototype.redSub=function(o){return t(this.red,"redSub works only with red numbers"),this.red.sub(this,o)},i.prototype.redISub=function(o){return t(this.red,"redISub works only with red numbers"),this.red.isub(this,o)},i.prototype.redShl=function(o){return t(this.red,"redShl works only with red numbers"),this.red.shl(this,o)},i.prototype.redMul=function(o){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,o),this.red.mul(this,o)},i.prototype.redIMul=function(o){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,o),this.red.imul(this,o)},i.prototype.redSqr=function(){return t(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},i.prototype.redISqr=function(){return t(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},i.prototype.redSqrt=function(){return t(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},i.prototype.redInvm=function(){return t(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},i.prototype.redNeg=function(){return t(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},i.prototype.redPow=function(o){return t(this.red&&!o.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,o)};var z={k256:null,p224:null,p192:null,p25519:null};function Q(v,o){this.name=v,this.p=new i(o,16),this.n=this.p.bitLength(),this.k=new i(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}Q.prototype._tmp=function(){var o=new i(null);return o.words=new Array(Math.ceil(this.n/13)),o},Q.prototype.ireduce=function(o){var l=o,c;do this.split(l,this.tmp),l=this.imulK(l),l=l.iadd(this.tmp),c=l.bitLength();while(c>this.n);var m=c<this.n?-1:l.ucmp(this.p);return m===0?(l.words[0]=0,l.length=1):m>0?l.isub(this.p):l.strip!==void 0?l.strip():l._strip(),l},Q.prototype.split=function(o,l){o.iushrn(this.n,0,l)},Q.prototype.imulK=function(o){return o.imul(this.k)};function it(){Q.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}r(it,Q),it.prototype.split=function(o,l){for(var c=4194303,m=Math.min(o.length,9),g=0;g<m;g++)l.words[g]=o.words[g];if(l.length=m,o.length<=9){o.words[0]=0,o.length=1;return}var M=o.words[9];for(l.words[l.length++]=M&c,g=10;g<o.length;g++){var P=o.words[g]|0;o.words[g-10]=(P&c)<<4|M>>>22,M=P}M>>>=22,o.words[g-10]=M,M===0&&o.length>10?o.length-=10:o.length-=9},it.prototype.imulK=function(o){o.words[o.length]=0,o.words[o.length+1]=0,o.length+=2;for(var l=0,c=0;c<o.length;c++){var m=o.words[c]|0;l+=m*977,o.words[c]=l&67108863,l=m*64+(l/67108864|0)}return o.words[o.length-1]===0&&(o.length--,o.words[o.length-1]===0&&o.length--),o};function at(){Q.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}r(at,Q);function Kt(){Q.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}r(Kt,Q);function $t(){Q.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}r($t,Q),$t.prototype.imulK=function(o){for(var l=0,c=0;c<o.length;c++){var m=(o.words[c]|0)*19+l,g=m&67108863;m>>>=26,o.words[c]=g,l=m}return l!==0&&(o.words[o.length++]=l),o},i._prime=function(o){if(z[o])return z[o];var l;if(o==="k256")l=new it;else if(o==="p224")l=new at;else if(o==="p192")l=new Kt;else if(o==="p25519")l=new $t;else throw new Error("Unknown prime "+o);return z[o]=l,l};function H(v){if(typeof v=="string"){var o=i._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}H.prototype._verify1=function(o){t(o.negative===0,"red works only with positives"),t(o.red,"red works only with red numbers")},H.prototype._verify2=function(o,l){t((o.negative|l.negative)===0,"red works only with positives"),t(o.red&&o.red===l.red,"red works only with red numbers")},H.prototype.imod=function(o){return this.prime?this.prime.ireduce(o)._forceRed(this):(h(o,o.umod(this.m)._forceRed(this)),o)},H.prototype.neg=function(o){return o.isZero()?o.clone():this.m.sub(o)._forceRed(this)},H.prototype.add=function(o,l){this._verify2(o,l);var c=o.add(l);return c.cmp(this.m)>=0&&c.isub(this.m),c._forceRed(this)},H.prototype.iadd=function(o,l){this._verify2(o,l);var c=o.iadd(l);return c.cmp(this.m)>=0&&c.isub(this.m),c},H.prototype.sub=function(o,l){this._verify2(o,l);var c=o.sub(l);return c.cmpn(0)<0&&c.iadd(this.m),c._forceRed(this)},H.prototype.isub=function(o,l){this._verify2(o,l);var c=o.isub(l);return c.cmpn(0)<0&&c.iadd(this.m),c},H.prototype.shl=function(o,l){return this._verify1(o),this.imod(o.ushln(l))},H.prototype.imul=function(o,l){return this._verify2(o,l),this.imod(o.imul(l))},H.prototype.mul=function(o,l){return this._verify2(o,l),this.imod(o.mul(l))},H.prototype.isqr=function(o){return this.imul(o,o.clone())},H.prototype.sqr=function(o){return this.mul(o,o)},H.prototype.sqrt=function(o){if(o.isZero())return o.clone();var l=this.m.andln(3);if(t(l%2===1),l===3){var c=this.m.add(new i(1)).iushrn(2);return this.pow(o,c)}for(var m=this.m.subn(1),g=0;!m.isZero()&&m.andln(1)===0;)g++,m.iushrn(1);t(!m.isZero());var M=new i(1).toRed(this),P=M.redNeg(),_=this.m.subn(1).iushrn(1),a=this.m.bitLength();for(a=new i(2*a*a).toRed(this);this.pow(a,_).cmp(P)!==0;)a.redIAdd(P);for(var b=this.pow(a,m),R=this.pow(o,m.addn(1).iushrn(1)),N=this.pow(o,m),L=g;N.cmp(M)!==0;){for(var V=N,tt=0;V.cmp(M)!==0;tt++)V=V.redSqr();t(tt<L);var ot=this.pow(b,new i(1).iushln(L-tt-1));R=R.redMul(ot),b=ot.redSqr(),N=N.redMul(b),L=tt}return R},H.prototype.invm=function(o){var l=o._invmp(this.m);return l.negative!==0?(l.negative=0,this.imod(l).redNeg()):this.imod(l)},H.prototype.pow=function(o,l){if(l.isZero())return new i(1).toRed(this);if(l.cmpn(1)===0)return o.clone();var c=4,m=new Array(1<<c);m[0]=new i(1).toRed(this),m[1]=o;for(var g=2;g<m.length;g++)m[g]=this.mul(m[g-1],o);var M=m[0],P=0,_=0,a=l.bitLength()%26;for(a===0&&(a=26),g=l.length-1;g>=0;g--){for(var b=l.words[g],R=a-1;R>=0;R--){var N=b>>R&1;if(M!==m[0]&&(M=this.sqr(M)),N===0&&P===0){_=0;continue}P<<=1,P|=N,_++,!(_!==c&&(g!==0||R!==0))&&(M=this.mul(M,m[P]),_=0,P=0)}a=26}return M},H.prototype.convertTo=function(o){var l=o.umod(this.m);return l===o?l.clone():l},H.prototype.convertFrom=function(o){var l=o.clone();return l.red=null,l},i.mont=function(o){return new rt(o)};function rt(v){H.call(this,v),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new i(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(rt,H),rt.prototype.convertTo=function(o){return this.imod(o.ushln(this.shift))},rt.prototype.convertFrom=function(o){var l=this.imod(o.mul(this.rinv));return l.red=null,l},rt.prototype.imul=function(o,l){if(o.isZero()||l.isZero())return o.words[0]=0,o.length=1,o;var c=o.imul(l),m=c.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),g=c.isub(m).iushrn(this.shift),M=g;return g.cmp(this.m)>=0?M=g.isub(this.m):g.cmpn(0)<0&&(M=g.iadd(this.m)),M._forceRed(this)},rt.prototype.mul=function(o,l){if(o.isZero()||l.isZero())return new i(0)._forceRed(this);var c=o.mul(l),m=c.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),g=c.isub(m).iushrn(this.shift),M=g;return g.cmp(this.m)>=0?M=g.isub(this.m):g.cmpn(0)<0&&(M=g.iadd(this.m)),M._forceRed(this)},rt.prototype.invm=function(o){var l=this.imod(o._invmp(this.m).mul(this.r2));return l._forceRed(this)}})(typeof vi>"u"||vi,sr)});var Zn={};Dr(Zn,{BASIS_POINT:()=>te,BASIS_POINT_MAX:()=>be,BIN_BOUND:()=>pe,BinUtils:()=>D,CetusDlmmSDK:()=>Ie,DEFAULT_MAX_WEIGHT:()=>je,DEFAULT_MIN_WEIGHT:()=>We,FEE_PRECISION:()=>Ze,FeeUtils:()=>Ri,IlmUtils:()=>Fi,MAX_BIN_ID:()=>kn,MAX_BIN_PER_POSITION:()=>ae,MAX_FEE_RATE:()=>Ue,MIN_BIN_ID:()=>xn,ONE:()=>He,PoolModule:()=>Be,REWARD_PERIOD:()=>Rn,REWARD_PERIOD_START_AT:()=>Fn,SCALE_OFFSET:()=>G,StrategyType:()=>Le,StrategyUtils:()=>ve,WeightUtils:()=>Xt,default:()=>Un,dlmmMainnet:()=>wi,dlmmTestnet:()=>Ni,generateRewardSchedule:()=>Ln,getRouterModule:()=>ki,parseBinInfo:()=>Ii,parseBinInfoList:()=>Ei,parseCurrentRewardPeriodEmission:()=>Wn,parseDlmmBasePool:()=>Bi,parseDlmmPool:()=>Pe,parseDlmmPosition:()=>Ke,parseLiquidityShares:()=>Nn,parsePartner:()=>Qe,parsePoolTransactionInfo:()=>xi,parseRewardPeriodEmission:()=>jn,parseStrategyType:()=>qn,parsedDlmmPosFeeData:()=>Oi,parsedDlmmPosRewardData:()=>Ci,parsedSwapQuoteData:()=>Ti,poolFilterEvenTypes:()=>Pr,safeMulAmount:()=>re});module.exports=Nr(Zn);var Or=require("@cetusprotocol/common-sdk");var nr=require("@cetusprotocol/common-sdk"),wi={env:"mainnet",full_rpc_url:nr.FullRpcUrlMainnet,dlmm_pool:{package_id:"0x8eb878ff59ecd9326697dc80f9df55ccfb050a711bb712981b1dc509f393cbdf",published_at:"0xa0f34a9aa8cd17e92c87bd93957c8daeba7fd45c2dbbba73f45ff47a93526c6b",version:1,config:{registry_id:"0xd436e82a6ef89b0ad4a1b8bd19b0e8e1c662e4a358a8dfe8221b1833abf3685b",pools_id:"0x09bb9bde6875ba06551617aec1ea7a653cda0f526ae7ce42bdc6ef4a713a3f19",global_config_id:"0xbf90603a8a7488a1440ed88e1d4c8d7b1f0c4cfd827dbb1c70655acc90258cc2",versioned_id:"0x8bdb4c81a2d507dbbf4a5762e64a3c39cae1fd201b47aae474eff8b31e1f384a",admin_cap_id:"0xec28f827eb125c80f316a0356b84eb52b98c6157bd443095843b1a3788518655",partners_id:"0x19c6643ead4b13f4066db107a8606694cff3a2d81b7f11c759da460b5ea23491"}},dlmm_router:{package_id:"0xb269f062e8f7fd2bd653a79405dea7c48cb0bf62b11e33c939637d52b1560a65",published_at:"0xb269f062e8f7fd2bd653a79405dea7c48cb0bf62b11e33c939637d52b1560a65",version:1}};var Ae=require("@mysten/sui/transactions"),X=require("@cetusprotocol/common-sdk");var or=require("@cetusprotocol/common-sdk");var me=class extends or.BaseError{constructor(e,t,r){super(e,t||"UnknownError",r)}static isDlmmErrorCode(e,t){return this.isErrorCode(e,t)}},K=(n,e,t)=>{let r={...t,stack:e instanceof Error?e.stack:void 0};throw e instanceof Error?new me(e.message,n,r):new me(e,n,r)};var $=require("@cetusprotocol/common-sdk"),Mr=bi(Ce());var _e=9e15,ce=1e9,yi="0123456789abcdef",ke="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Re="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Mi={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-_e,maxE:_e,crypto:!1},dr,se,Z=!0,De="[DecimalError] ",fe=De+"Invalid argument: ",fr=De+"Precision limit exceeded",cr=De+"crypto unavailable",hr="[object Decimal]",Vt=Math.floor,Ht=Math.pow,qr=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Lr=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,jr=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,pr=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,ie=1e7,W=7,Wr=9007199254740991,Ur=ke.length-1,Pi=Re.length-1,E={toStringTag:hr};E.absoluteValue=E.abs=function(){var n=new this.constructor(this);return n.s<0&&(n.s=1),q(n)};E.ceil=function(){return q(new this.constructor(this),this.e+1,2)};E.clampedTo=E.clamp=function(n,e){var t,r=this,i=r.constructor;if(n=new i(n),e=new i(e),!n.s||!e.s)return new i(NaN);if(n.gt(e))throw Error(fe+e);return t=r.cmp(n),t<0?n:r.cmp(e)>0?e:new i(r)};E.comparedTo=E.cmp=function(n){var e,t,r,i,s=this,u=s.d,d=(n=new s.constructor(n)).d,f=s.s,h=n.s;if(!u||!d)return!f||!h?NaN:f!==h?f:u===d?0:!u^f<0?1:-1;if(!u[0]||!d[0])return u[0]?f:d[0]?-h:0;if(f!==h)return f;if(s.e!==n.e)return s.e>n.e^f<0?1:-1;for(r=u.length,i=d.length,e=0,t=r<i?r:i;e<t;++e)if(u[e]!==d[e])return u[e]>d[e]^f<0?1:-1;return r===i?0:r>i^f<0?1:-1};E.cosine=E.cos=function(){var n,e,t=this,r=t.constructor;return t.d?t.d[0]?(n=r.precision,e=r.rounding,r.precision=n+Math.max(t.e,t.sd())+W,r.rounding=1,t=Zr(r,wr(r,t)),r.precision=n,r.rounding=e,q(se==2||se==3?t.neg():t,n,e,!0)):new r(1):new r(NaN)};E.cubeRoot=E.cbrt=function(){var n,e,t,r,i,s,u,d,f,h,p=this,w=p.constructor;if(!p.isFinite()||p.isZero())return new w(p);for(Z=!1,s=p.s*Ht(p.s*p,1/3),!s||Math.abs(s)==1/0?(t=zt(p.d),n=p.e,(s=(n-t.length+1)%3)&&(t+=s==1||s==-2?"0":"00"),s=Ht(t,1/3),n=Vt((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 w(t),r.s=p.s):r=new w(s.toString()),u=(n=w.precision)+3;;)if(d=r,f=d.times(d).times(d),h=f.plus(p),r=nt(h.plus(p).times(d),h.plus(f),u+2,1),zt(d.d).slice(0,u)===(t=zt(r.d)).slice(0,u))if(t=t.slice(u-3,u+1),t=="9999"||!i&&t=="4999"){if(!i&&(q(d,n+1,0),d.times(d).times(d).eq(p))){r=d;break}u+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(q(r,n+1,1),e=!r.times(r).times(r).eq(p));break}return Z=!0,q(r,n,w.rounding,e)};E.decimalPlaces=E.dp=function(){var n,e=this.d,t=NaN;if(e){if(n=e.length-1,t=(n-Vt(this.e/W))*W,n=e[n],n)for(;n%10==0;n/=10)t--;t<0&&(t=0)}return t};E.dividedBy=E.div=function(n){return nt(this,new this.constructor(n))};E.dividedToIntegerBy=E.divToInt=function(n){var e=this,t=e.constructor;return q(nt(e,new t(n),0,1,1),t.precision,t.rounding)};E.equals=E.eq=function(n){return this.cmp(n)===0};E.floor=function(){return q(new this.constructor(this),this.e+1,3)};E.greaterThan=E.gt=function(n){return this.cmp(n)>0};E.greaterThanOrEqualTo=E.gte=function(n){var e=this.cmp(n);return e==1||e===0};E.hyperbolicCosine=E.cosh=function(){var n,e,t,r,i,s=this,u=s.constructor,d=new u(1);if(!s.isFinite())return new u(s.s?1/0:NaN);if(s.isZero())return d;t=u.precision,r=u.rounding,u.precision=t+Math.max(s.e,s.sd())+4,u.rounding=1,i=s.d.length,i<32?(n=Math.ceil(i/3),e=(1/qe(4,n)).toString()):(n=16,e="2.3283064365386962890625e-10"),s=ge(u,1,s.times(e),new u(1),!0);for(var f,h=n,p=new u(8);h--;)f=s.times(s),s=d.minus(f.times(p.minus(f.times(p))));return q(s,u.precision=t,u.rounding=r,!0)};E.hyperbolicSine=E.sinh=function(){var n,e,t,r,i=this,s=i.constructor;if(!i.isFinite()||i.isZero())return new s(i);if(e=s.precision,t=s.rounding,s.precision=e+Math.max(i.e,i.sd())+4,s.rounding=1,r=i.d.length,r<3)i=ge(s,2,i,i,!0);else{n=1.4*Math.sqrt(r),n=n>16?16:n|0,i=i.times(1/qe(5,n)),i=ge(s,2,i,i,!0);for(var u,d=new s(5),f=new s(16),h=new s(20);n--;)u=i.times(i),i=i.times(d.plus(u.times(f.times(u).plus(h))))}return s.precision=e,s.rounding=t,q(i,e,t,!0)};E.hyperbolicTangent=E.tanh=function(){var n,e,t=this,r=t.constructor;return t.isFinite()?t.isZero()?new r(t):(n=r.precision,e=r.rounding,r.precision=n+7,r.rounding=1,nt(t.sinh(),t.cosh(),r.precision=n,r.rounding=e)):new r(t.s)};E.inverseCosine=E.acos=function(){var n=this,e=n.constructor,t=n.abs().cmp(1),r=e.precision,i=e.rounding;return t!==-1?t===0?n.isNeg()?ne(e,r,i):new e(0):new e(NaN):n.isZero()?ne(e,r+4,i).times(.5):(e.precision=r+6,e.rounding=1,n=new e(1).minus(n).div(n.plus(1)).sqrt().atan(),e.precision=r,e.rounding=i,n.times(2))};E.inverseHyperbolicCosine=E.acosh=function(){var n,e,t=this,r=t.constructor;return t.lte(1)?new r(t.eq(1)?0:NaN):t.isFinite()?(n=r.precision,e=r.rounding,r.precision=n+Math.max(Math.abs(t.e),t.sd())+4,r.rounding=1,Z=!1,t=t.times(t).minus(1).sqrt().plus(t),Z=!0,r.precision=n,r.rounding=e,t.ln()):new r(t)};E.inverseHyperbolicSine=E.asinh=function(){var n,e,t=this,r=t.constructor;return!t.isFinite()||t.isZero()?new r(t):(n=r.precision,e=r.rounding,r.precision=n+2*Math.max(Math.abs(t.e),t.sd())+6,r.rounding=1,Z=!1,t=t.times(t).plus(1).sqrt().plus(t),Z=!0,r.precision=n,r.rounding=e,t.ln())};E.inverseHyperbolicTangent=E.atanh=function(){var n,e,t,r,i=this,s=i.constructor;return i.isFinite()?i.e>=0?new s(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(n=s.precision,e=s.rounding,r=i.sd(),Math.max(r,n)<2*-i.e-1?q(new s(i),n,e,!0):(s.precision=t=r-i.e,i=nt(i.plus(1),new s(1).minus(i),t+n,1),s.precision=n+4,s.rounding=1,i=i.ln(),s.precision=n,s.rounding=e,i.times(.5))):new s(NaN)};E.inverseSine=E.asin=function(){var n,e,t,r,i=this,s=i.constructor;return i.isZero()?new s(i):(e=i.abs().cmp(1),t=s.precision,r=s.rounding,e!==-1?e===0?(n=ne(s,t+4,r).times(.5),n.s=i.s,n):new s(NaN):(s.precision=t+6,s.rounding=1,i=i.div(new s(1).minus(i.times(i)).sqrt().plus(1)).atan(),s.precision=t,s.rounding=r,i.times(2)))};E.inverseTangent=E.atan=function(){var n,e,t,r,i,s,u,d,f,h=this,p=h.constructor,w=p.precision,y=p.rounding;if(h.isFinite()){if(h.isZero())return new p(h);if(h.abs().eq(1)&&w+4<=Pi)return u=ne(p,w+4,y).times(.25),u.s=h.s,u}else{if(!h.s)return new p(NaN);if(w+4<=Pi)return u=ne(p,w+4,y).times(.5),u.s=h.s,u}for(p.precision=d=w+10,p.rounding=1,t=Math.min(28,d/W+2|0),n=t;n;--n)h=h.div(h.times(h).plus(1).sqrt().plus(1));for(Z=!1,e=Math.ceil(d/W),r=1,f=h.times(h),u=new p(h),i=h;n!==-1;)if(i=i.times(f),s=u.minus(i.div(r+=2)),i=i.times(f),u=s.plus(i.div(r+=2)),u.d[e]!==void 0)for(n=e;u.d[n]===s.d[n]&&n--;);return t&&(u=u.times(2<<t-1)),Z=!0,q(u,p.precision=w,p.rounding=y,!0)};E.isFinite=function(){return!!this.d};E.isInteger=E.isInt=function(){return!!this.d&&Vt(this.e/W)>this.d.length-2};E.isNaN=function(){return!this.s};E.isNegative=E.isNeg=function(){return this.s<0};E.isPositive=E.isPos=function(){return this.s>0};E.isZero=function(){return!!this.d&&this.d[0]===0};E.lessThan=E.lt=function(n){return this.cmp(n)<0};E.lessThanOrEqualTo=E.lte=function(n){return this.cmp(n)<1};E.logarithm=E.log=function(n){var e,t,r,i,s,u,d,f,h=this,p=h.constructor,w=p.precision,y=p.rounding,A=5;if(n==null)n=new p(10),e=!0;else{if(n=new p(n),t=n.d,n.s<0||!t||!t[0]||n.eq(1))return new p(NaN);e=n.eq(10)}if(t=h.d,h.s<0||!t||!t[0]||h.eq(1))return new p(t&&!t[0]?-1/0:h.s!=1?NaN:t?0:1/0);if(e)if(t.length>1)s=!0;else{for(i=t[0];i%10===0;)i/=10;s=i!==1}if(Z=!1,d=w+A,u=de(h,d),r=e?Fe(p,d+10):de(n,d),f=nt(u,r,d,1),ye(f.d,i=w,y))do if(d+=10,u=de(h,d),r=e?Fe(p,d+10):de(n,d),f=nt(u,r,d,1),!s){+zt(f.d).slice(i+1,i+15)+1==1e14&&(f=q(f,w+1,0));break}while(ye(f.d,i+=10,y));return Z=!0,q(f,w,y)};E.minus=E.sub=function(n){var e,t,r,i,s,u,d,f,h,p,w,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(h=A.d,y=n.d,d=B.precision,f=B.rounding,!h[0]||!y[0]){if(y[0])n.s=-n.s;else if(h[0])n=new B(A);else return new B(f===3?-0:0);return Z?q(n,d,f):n}if(t=Vt(n.e/W),p=Vt(A.e/W),h=h.slice(),s=p-t,s){for(w=s<0,w?(e=h,s=-s,u=y.length):(e=y,t=p,u=h.length),r=Math.max(Math.ceil(d/W),u)+2,s>r&&(s=r,e.length=1),e.reverse(),r=s;r--;)e.push(0);e.reverse()}else{for(r=h.length,u=y.length,w=r<u,w&&(u=r),r=0;r<u;r++)if(h[r]!=y[r]){w=h[r]<y[r];break}s=0}for(w&&(e=h,h=y,y=e,n.s=-n.s),u=h.length,r=y.length-u;r>0;--r)h[u++]=0;for(r=y.length;r>s;){if(h[--r]<y[r]){for(i=r;i&&h[--i]===0;)h[i]=ie-1;--h[i],h[r]+=ie}h[r]-=y[r]}for(;h[--u]===0;)h.pop();for(;h[0]===0;h.shift())--t;return h[0]?(n.d=h,n.e=Ne(h,t),Z?q(n,d,f):n):new B(f===3?-0:0)};E.modulo=E.mod=function(n){var e,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]?q(new r(t),r.precision,r.rounding):(Z=!1,r.modulo==9?(e=nt(t,n.abs(),0,3,1),e.s*=n.s):e=nt(t,n,0,r.modulo,1),e=e.times(n),Z=!0,t.minus(e))};E.naturalExponential=E.exp=function(){return Ai(this)};E.naturalLogarithm=E.ln=function(){return de(this)};E.negated=E.neg=function(){var n=new this.constructor(this);return n.s=-n.s,q(n)};E.plus=E.add=function(n){var e,t,r,i,s,u,d,f,h,p,w=this,y=w.constructor;if(n=new y(n),!w.d||!n.d)return!w.s||!n.s?n=new y(NaN):w.d||(n=new y(n.d||w.s===n.s?w:NaN)),n;if(w.s!=n.s)return n.s=-n.s,w.minus(n);if(h=w.d,p=n.d,d=y.precision,f=y.rounding,!h[0]||!p[0])return p[0]||(n=new y(w)),Z?q(n,d,f):n;if(s=Vt(w.e/W),r=Vt(n.e/W),h=h.slice(),i=s-r,i){for(i<0?(t=h,i=-i,u=p.length):(t=p,r=s,u=h.length),s=Math.ceil(d/W),u=s>u?s+1:u+1,i>u&&(i=u,t.length=1),t.reverse();i--;)t.push(0);t.reverse()}for(u=h.length,i=p.length,u-i<0&&(i=u,t=p,p=h,h=t),e=0;i;)e=(h[--i]=h[i]+p[i]+e)/ie|0,h[i]%=ie;for(e&&(h.unshift(e),++r),u=h.length;h[--u]==0;)h.pop();return n.d=h,n.e=Ne(h,r),Z?q(n,d,f):n};E.precision=E.sd=function(n){var e,t=this;if(n!==void 0&&n!==!!n&&n!==1&&n!==0)throw Error(fe+n);return t.d?(e=mr(t.d),n&&t.e+1>e&&(e=t.e+1)):e=NaN,e};E.round=function(){var n=this,e=n.constructor;return q(new e(n),n.e+1,e.rounding)};E.sine=E.sin=function(){var n,e,t=this,r=t.constructor;return t.isFinite()?t.isZero()?new r(t):(n=r.precision,e=r.rounding,r.precision=n+Math.max(t.e,t.sd())+W,r.rounding=1,t=Qr(r,wr(r,t)),r.precision=n,r.rounding=e,q(se>2?t.neg():t,n,e,!0)):new r(NaN)};E.squareRoot=E.sqrt=function(){var n,e,t,r,i,s,u=this,d=u.d,f=u.e,h=u.s,p=u.constructor;if(h!==1||!d||!d[0])return new p(!h||h<0&&(!d||d[0])?NaN:d?u:1/0);for(Z=!1,h=Math.sqrt(+u),h==0||h==1/0?(e=zt(d),(e.length+f)%2==0&&(e+="0"),h=Math.sqrt(e),f=Vt((f+1)/2)-(f<0||f%2),h==1/0?e="5e"+f:(e=h.toExponential(),e=e.slice(0,e.indexOf("e")+1)+f),r=new p(e)):r=new p(h.toString()),t=(f=p.precision)+3;;)if(s=r,r=s.plus(nt(u,s,t+2,1)).times(.5),zt(s.d).slice(0,t)===(e=zt(r.d)).slice(0,t))if(e=e.slice(t-3,t+1),e=="9999"||!i&&e=="4999"){if(!i&&(q(s,f+1,0),s.times(s).eq(u))){r=s;break}t+=4,i=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(q(r,f+1,1),n=!r.times(r).eq(u));break}return Z=!0,q(r,f,p.rounding,n)};E.tangent=E.tan=function(){var n,e,t=this,r=t.constructor;return t.isFinite()?t.isZero()?new r(t):(n=r.precision,e=r.rounding,r.precision=n+10,r.rounding=1,t=t.sin(),t.s=1,t=nt(t,new r(1).minus(t.times(t)).sqrt(),n+10,0),r.precision=n,r.rounding=e,q(se==2||se==4?t.neg():t,n,e,!0)):new r(NaN)};E.times=E.mul=function(n){var e,t,r,i,s,u,d,f,h,p=this,w=p.constructor,y=p.d,A=(n=new w(n)).d;if(n.s*=p.s,!y||!y[0]||!A||!A[0])return new w(!n.s||y&&!y[0]&&!A||A&&!A[0]&&!y?NaN:!y||!A?n.s/0:n.s*0);for(t=Vt(p.e/W)+Vt(n.e/W),f=y.length,h=A.length,f<h&&(s=y,y=A,A=s,u=f,f=h,h=u),s=[],u=f+h,r=u;r--;)s.push(0);for(r=h;--r>=0;){for(e=0,i=f+r;i>r;)d=s[i]+A[r]*y[i-r-1]+e,s[i--]=d%ie|0,e=d/ie|0;s[i]=(s[i]+e)%ie|0}for(;!s[--u];)s.pop();return e?++t:s.shift(),n.d=s,n.e=Ne(s,t),Z?q(n,w.precision,w.rounding):n};E.toBinary=function(n,e){return Si(this,2,n,e)};E.toDecimalPlaces=E.toDP=function(n,e){var t=this,r=t.constructor;return t=new r(t),n===void 0?t:(Jt(n,0,ce),e===void 0?e=r.rounding:Jt(e,0,8),q(t,n+t.e+1,e))};E.toExponential=function(n,e){var t,r=this,i=r.constructor;return n===void 0?t=oe(r,!0):(Jt(n,0,ce),e===void 0?e=i.rounding:Jt(e,0,8),r=q(new i(r),n+1,e),t=oe(r,!0,n+1)),r.isNeg()&&!r.isZero()?"-"+t:t};E.toFixed=function(n,e){var t,r,i=this,s=i.constructor;return n===void 0?t=oe(i):(Jt(n,0,ce),e===void 0?e=s.rounding:Jt(e,0,8),r=q(new s(i),n+i.e+1,e),t=oe(r,!1,n+r.e+1)),i.isNeg()&&!i.isZero()?"-"+t:t};E.toFraction=function(n){var e,t,r,i,s,u,d,f,h,p,w,y,A=this,B=A.d,S=A.constructor;if(!B)return new S(A);if(h=t=new S(1),r=f=new S(0),e=new S(r),s=e.e=mr(B)-A.e-1,u=s%W,e.d[0]=Ht(10,u<0?W+u:u),n==null)n=s>0?e:h;else{if(d=new S(n),!d.isInt()||d.lt(h))throw Error(fe+d);n=d.gt(e)?s>0?e:h:d}for(Z=!1,d=new S(zt(B)),p=S.precision,S.precision=s=B.length*W*2;w=nt(d,e,0,1,1),i=t.plus(w.times(r)),i.cmp(n)!=1;)t=r,r=i,i=h,h=f.plus(w.times(i)),f=i,i=e,e=d.minus(w.times(i)),d=i;return i=nt(n.minus(t),r,0,1,1),f=f.plus(i.times(h)),t=t.plus(i.times(r)),f.s=h.s=A.s,y=nt(h,r,s,1).minus(A).abs().cmp(nt(f,t,s,1).minus(A).abs())<1?[h,r]:[f,t],S.precision=p,Z=!0,y};E.toHexadecimal=E.toHex=function(n,e){return Si(this,16,n,e)};E.toNearest=function(n,e){var t=this,r=t.constructor;if(t=new r(t),n==null){if(!t.d)return t;n=new r(1),e=r.rounding}else{if(n=new r(n),e===void 0?e=r.rounding:Jt(e,0,8),!t.d)return n.s?t:n;if(!n.d)return n.s&&(n.s=t.s),n}return n.d[0]?(Z=!1,t=nt(t,n,0,e,1).times(n),Z=!0,q(t)):(n.s=t.s,t=n),t};E.toNumber=function(){return+this};E.toOctal=function(n,e){return Si(this,8,n,e)};E.toPower=E.pow=function(n){var e,t,r,i,s,u,d=this,f=d.constructor,h=+(n=new f(n));if(!d.d||!n.d||!d.d[0]||!n.d[0])return new f(Ht(+d,h));if(d=new f(d),d.eq(1))return d;if(r=f.precision,s=f.rounding,n.eq(1))return q(d,r,s);if(e=Vt(n.e/W),e>=n.d.length-1&&(t=h<0?-h:h)<=Wr)return i=_r(f,d,t,r),n.s<0?new f(1).div(i):q(i,r,s);if(u=d.s,u<0){if(e<n.d.length-1)return new f(NaN);if((n.d[e]&1)==0&&(u=1),d.e==0&&d.d[0]==1&&d.d.length==1)return d.s=u,d}return t=Ht(+d,h),e=t==0||!isFinite(t)?Vt(h*(Math.log("0."+zt(d.d))/Math.LN10+d.e+1)):new f(t+"").e,e>f.maxE+1||e<f.minE-1?new f(e>0?u/0:0):(Z=!1,f.rounding=d.s=1,t=Math.min(12,(e+"").length),i=Ai(n.times(de(d,r+t)),r),i.d&&(i=q(i,r+5,1),ye(i.d,r,s)&&(e=r+10,i=q(Ai(n.times(de(d,e+t)),e),e+5,1),+zt(i.d).slice(r+1,r+15)+1==1e14&&(i=q(i,r+1,0)))),i.s=u,Z=!0,f.rounding=s,q(i,r,s))};E.toPrecision=function(n,e){var t,r=this,i=r.constructor;return n===void 0?t=oe(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(Jt(n,1,ce),e===void 0?e=i.rounding:Jt(e,0,8),r=q(new i(r),n,e),t=oe(r,n<=r.e||r.e<=i.toExpNeg,n)),r.isNeg()&&!r.isZero()?"-"+t:t};E.toSignificantDigits=E.toSD=function(n,e){var t=this,r=t.constructor;return n===void 0?(n=r.precision,e=r.rounding):(Jt(n,1,ce),e===void 0?e=r.rounding:Jt(e,0,8)),q(new r(t),n,e)};E.toString=function(){var n=this,e=n.constructor,t=oe(n,n.e<=e.toExpNeg||n.e>=e.toExpPos);return n.isNeg()&&!n.isZero()?"-"+t:t};E.truncated=E.trunc=function(){return q(new this.constructor(this),this.e+1,1)};E.valueOf=E.toJSON=function(){var n=this,e=n.constructor,t=oe(n,n.e<=e.toExpNeg||n.e>=e.toExpPos);return n.isNeg()?"-"+t:t};function zt(n){var e,t,r,i=n.length-1,s="",u=n[0];if(i>0){for(s+=u,e=1;e<i;e++)r=n[e]+"",t=W-r.length,t&&(s+=ue(t)),s+=r;u=n[e],r=u+"",t=W-r.length,t&&(s+=ue(t))}else if(u===0)return"0";for(;u%10===0;)u/=10;return s+u}function Jt(n,e,t){if(n!==~~n||n<e||n>t)throw Error(fe+n)}function ye(n,e,t,r){var i,s,u,d;for(s=n[0];s>=10;s/=10)--e;return--e<0?(e+=W,i=0):(i=Math.ceil((e+1)/W),e%=W),s=Ht(10,W-e),d=n[i]%s|0,r==null?e<3?(e==0?d=d/100|0:e==1&&(d=d/10|0),u=t<4&&d==99999||t>3&&d==49999||d==5e4||d==0):u=(t<4&&d+1==s||t>3&&d+1==s/2)&&(n[i+1]/s/100|0)==Ht(10,e-2)-1||(d==s/2||d==0)&&(n[i+1]/s/100|0)==0:e<4?(e==0?d=d/1e3|0:e==1?d=d/100|0:e==2&&(d=d/10|0),u=(r||t<4)&&d==9999||!r&&t>3&&d==4999):u=((r||t<4)&&d+1==s||!r&&t>3&&d+1==s/2)&&(n[i+1]/s/1e3|0)==Ht(10,e-3)-1,u}function Te(n,e,t){for(var r,i=[0],s,u=0,d=n.length;u<d;){for(s=i.length;s--;)i[s]*=e;for(i[0]+=yi.indexOf(n.charAt(u++)),r=0;r<i.length;r++)i[r]>t-1&&(i[r+1]===void 0&&(i[r+1]=0),i[r+1]+=i[r]/t|0,i[r]%=t)}return i.reverse()}function Zr(n,e){var t,r,i;if(e.isZero())return e;r=e.d.length,r<32?(t=Math.ceil(r/3),i=(1/qe(4,t)).toString()):(t=16,i="2.3283064365386962890625e-10"),n.precision+=t,e=ge(n,1,e.times(i),new n(1));for(var s=t;s--;){var u=e.times(e);e=u.times(u).minus(u).times(8).plus(1)}return n.precision-=t,e}var nt=(function(){function n(r,i,s){var u,d=0,f=r.length;for(r=r.slice();f--;)u=r[f]*i+d,r[f]=u%s|0,d=u/s|0;return d&&r.unshift(d),r}function e(r,i,s,u){var d,f;if(s!=u)f=s>u?1:-1;else for(d=f=0;d<s;d++)if(r[d]!=i[d]){f=r[d]>i[d]?1:-1;break}return f}function t(r,i,s,u){for(var d=0;s--;)r[s]-=d,d=r[s]<i[s]?1:0,r[s]=d*u+r[s]-i[s];for(;!r[0]&&r.length>1;)r.shift()}return function(r,i,s,u,d,f){var h,p,w,y,A,B,S,T,x,k,I,C,z,Q,it,at,Kt,$t,H,rt,v=r.constructor,o=r.s==i.s?1:-1,l=r.d,c=i.d;if(!l||!l[0]||!c||!c[0])return new v(!r.s||!i.s||(l?c&&l[0]==c[0]:!c)?NaN:l&&l[0]==0||!c?o*0:o/0);for(f?(A=1,p=r.e-i.e):(f=ie,A=W,p=Vt(r.e/A)-Vt(i.e/A)),H=c.length,Kt=l.length,x=new v(o),k=x.d=[],w=0;c[w]==(l[w]||0);w++);if(c[w]>(l[w]||0)&&p--,s==null?(Q=s=v.precision,u=v.rounding):d?Q=s+(r.e-i.e)+1:Q=s,Q<0)k.push(1),B=!0;else{if(Q=Q/A+2|0,w=0,H==1){for(y=0,c=c[0],Q++;(w<Kt||y)&&Q--;w++)it=y*f+(l[w]||0),k[w]=it/c|0,y=it%c|0;B=y||w<Kt}else{for(y=f/(c[0]+1)|0,y>1&&(c=n(c,y,f),l=n(l,y,f),H=c.length,Kt=l.length),at=H,I=l.slice(0,H),C=I.length;C<H;)I[C++]=0;rt=c.slice(),rt.unshift(0),$t=c[0],c[1]>=f/2&&++$t;do y=0,h=e(c,I,H,C),h<0?(z=I[0],H!=C&&(z=z*f+(I[1]||0)),y=z/$t|0,y>1?(y>=f&&(y=f-1),S=n(c,y,f),T=S.length,C=I.length,h=e(S,I,T,C),h==1&&(y--,t(S,H<T?rt:c,T,f))):(y==0&&(h=y=1),S=c.slice()),T=S.length,T<C&&S.unshift(0),t(I,S,C,f),h==-1&&(C=I.length,h=e(c,I,H,C),h<1&&(y++,t(I,H<C?rt:c,C,f))),C=I.length):h===0&&(y++,I=[0]),k[w++]=y,h&&I[0]?I[C++]=l[at]||0:(I=[l[at]],C=1);while((at++<Kt||I[0]!==void 0)&&Q--);B=I[0]!==void 0}k[0]||k.shift()}if(A==1)x.e=p,dr=B;else{for(w=1,y=k[0];y>=10;y/=10)w++;x.e=w+p*A-1,q(x,d?s+x.e+1:s,u,B)}return x}})();function q(n,e,t,r){var i,s,u,d,f,h,p,w,y,A=n.constructor;t:if(e!=null){if(w=n.d,!w)return n;for(i=1,d=w[0];d>=10;d/=10)i++;if(s=e-i,s<0)s+=W,u=e,p=w[y=0],f=p/Ht(10,i-u-1)%10|0;else if(y=Math.ceil((s+1)/W),d=w.length,y>=d)if(r){for(;d++<=y;)w.push(0);p=f=0,i=1,s%=W,u=s-W+1}else break t;else{for(p=d=w[y],i=1;d>=10;d/=10)i++;s%=W,u=s-W+i,f=u<0?0:p/Ht(10,i-u-1)%10|0}if(r=r||e<0||w[y+1]!==void 0||(u<0?p:p%Ht(10,i-u-1)),h=t<4?(f||r)&&(t==0||t==(n.s<0?3:2)):f>5||f==5&&(t==4||r||t==6&&(s>0?u>0?p/Ht(10,i-u):0:w[y-1])%10&1||t==(n.s<0?8:7)),e<1||!w[0])return w.length=0,h?(e-=n.e+1,w[0]=Ht(10,(W-e%W)%W),n.e=-e||0):w[0]=n.e=0,n;if(s==0?(w.length=y,d=1,y--):(w.length=y+1,d=Ht(10,W-s),w[y]=u>0?(p/Ht(10,i-u)%Ht(10,u)|0)*d:0),h)for(;;)if(y==0){for(s=1,u=w[0];u>=10;u/=10)s++;for(u=w[0]+=d,d=1;u>=10;u/=10)d++;s!=d&&(n.e++,w[0]==ie&&(w[0]=1));break}else{if(w[y]+=d,w[y]!=ie)break;w[y--]=0,d=1}for(s=w.length;w[--s]===0;)w.pop()}return Z&&(n.e>A.maxE?(n.d=null,n.e=NaN):n.e<A.minE&&(n.e=0,n.d=[0])),n}function oe(n,e,t){if(!n.isFinite())return br(n);var r,i=n.e,s=zt(n.d),u=s.length;return e?(t&&(r=t-u)>0?s=s.charAt(0)+"."+s.slice(1)+ue(r):u>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(n.e<0?"e":"e+")+n.e):i<0?(s="0."+ue(-i-1)+s,t&&(r=t-u)>0&&(s+=ue(r))):i>=u?(s+=ue(i+1-u),t&&(r=t-i-1)>0&&(s=s+"."+ue(r))):((r=i+1)<u&&(s=s.slice(0,r)+"."+s.slice(r)),t&&(r=t-u)>0&&(i+1===u&&(s+="."),s+=ue(r))),s}function Ne(n,e){var t=n[0];for(e*=W;t>=10;t/=10)e++;return e}function Fe(n,e,t){if(e>Ur)throw Z=!0,t&&(n.precision=t),Error(fr);return q(new n(ke),e,1,!0)}function ne(n,e,t){if(e>Pi)throw Error(fr);return q(new n(Re),e,t,!0)}function mr(n){var e=n.length-1,t=e*W+1;if(e=n[e],e){for(;e%10==0;e/=10)t--;for(e=n[0];e>=10;e/=10)t++}return t}function ue(n){for(var e="";n--;)e+="0";return e}function _r(n,e,t,r){var i,s=new n(1),u=Math.ceil(r/W+4);for(Z=!1;;){if(t%2&&(s=s.times(e),lr(s.d,u)&&(i=!0)),t=Vt(t/2),t===0){t=s.d.length-1,i&&s.d[t]===0&&++s.d[t];break}e=e.times(e),lr(e.d,u)}return Z=!0,s}function ar(n){return n.d[n.d.length-1]&1}function gr(n,e,t){for(var r,i,s=new n(e[0]),u=0;++u<e.length;){if(i=new n(e[u]),!i.s){s=i;break}r=s.cmp(i),(r===t||r===0&&s.s===t)&&(s=i)}return s}function Ai(n,e){var t,r,i,s,u,d,f,h=0,p=0,w=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(e==null?(Z=!1,f=B):f=e,d=new y(.03125);n.e>-2;)n=n.times(d),w+=5;for(r=Math.log(Ht(2,w))/Math.LN10*2+5|0,f+=r,t=s=u=new y(1),y.precision=f;;){if(s=q(s.times(n),f,1),t=t.times(++p),d=u.plus(nt(s,t,f,1)),zt(d.d).slice(0,f)===zt(u.d).slice(0,f)){for(i=w;i--;)u=q(u.times(u),f,1);if(e==null)if(h<3&&ye(u.d,f-r,A,h))y.precision=f+=10,t=s=d=new y(1),p=0,h++;else return q(u,y.precision=B,A,Z=!0);else return y.precision=B,u}u=d}}function de(n,e){var t,r,i,s,u,d,f,h,p,w,y,A=1,B=10,S=n,T=S.d,x=S.constructor,k=x.rounding,I=x.precision;if(S.s<0||!T||!T[0]||!S.e&&T[0]==1&&T.length==1)return new x(T&&!T[0]?-1/0:S.s!=1?NaN:T?0:S);if(e==null?(Z=!1,p=I):p=e,x.precision=p+=B,t=zt(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=zt(S.d),r=t.charAt(0),A++;s=S.e,r>1?(S=new x("0."+t),s++):S=new x(r+"."+t.slice(1))}else return h=Fe(x,p+2,I).times(s+""),S=de(new x(r+"."+t.slice(1)),p-B).plus(h),x.precision=I,e==null?q(S,I,k,Z=!0):S;for(w=S,f=u=S=nt(S.minus(1),S.plus(1),p,1),y=q(S.times(S),p,1),i=3;;){if(u=q(u.times(y),p,1),h=f.plus(nt(u,new x(i),p,1)),zt(h.d).slice(0,p)===zt(f.d).slice(0,p))if(f=f.times(2),s!==0&&(f=f.plus(Fe(x,p+2,I).times(s+""))),f=nt(f,new x(A),p,1),e==null)if(ye(f.d,p-B,k,d))x.precision=p+=B,h=u=S=nt(w.minus(1),w.plus(1),p,1),y=q(S.times(S),p,1),i=d=1;else return q(f,x.precision=I,k,Z=!0);else return x.precision=I,f;f=h,i+=2}}function br(n){return String(n.s*n.s/0)}function xe(n,e){var t,r,i;for((t=e.indexOf("."))>-1&&(e=e.replace(".","")),(r=e.search(/e/i))>0?(t<0&&(t=r),t+=+e.slice(r+1),e=e.substring(0,r)):t<0&&(t=e.length),r=0;e.charCodeAt(r)===48;r++);for(i=e.length;e.charCodeAt(i-1)===48;--i);if(e=e.slice(r,i),e){if(i-=r,n.e=t=t-r-1,n.d=[],r=(t+1)%W,t<0&&(r+=W),r<i){for(r&&n.d.push(+e.slice(0,r)),i-=W;r<i;)n.d.push(+e.slice(r,r+=W));e=e.slice(r),r=W-e.length}else r-=i;for(;r--;)e+="0";n.d.push(+e),Z&&(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 Hr(n,e){var t,r,i,s,u,d,f,h,p;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),pr.test(e))return xe(n,e)}else if(e==="Infinity"||e==="NaN")return+e||(n.s=NaN),n.e=NaN,n.d=null,n;if(Lr.test(e))t=16,e=e.toLowerCase();else if(qr.test(e))t=2;else if(jr.test(e))t=8;else throw Error(fe+e);for(s=e.search(/p/i),s>0?(f=+e.slice(s+1),e=e.substring(2,s)):e=e.slice(2),s=e.indexOf("."),u=s>=0,r=n.constructor,u&&(e=e.replace(".",""),d=e.length,s=d-s,i=_r(r,new r(t),s,s*2)),h=Te(e,t,ie),p=h.length-1,s=p;h[s]===0;--s)h.pop();return s<0?new r(n.s*0):(n.e=Ne(h,p),n.d=h,Z=!1,u&&(n=nt(n,i,d*4)),f&&(n=n.times(Math.abs(f)<54?Ht(2,f):Me.pow(2,f))),Z=!0,n)}function Qr(n,e){var t,r=e.d.length;if(r<3)return e.isZero()?e:ge(n,2,e,e);t=1.4*Math.sqrt(r),t=t>16?16:t|0,e=e.times(1/qe(5,t)),e=ge(n,2,e,e);for(var i,s=new n(5),u=new n(16),d=new n(20);t--;)i=e.times(e),e=e.times(s.plus(i.times(u.times(i).minus(d))));return e}function ge(n,e,t,r,i){var s,u,d,f,h=1,p=n.precision,w=Math.ceil(p/W);for(Z=!1,f=t.times(t),d=new n(r);;){if(u=nt(d.times(f),new n(e++*e++),p,1),d=i?r.plus(u):r.minus(u),r=nt(u.times(f),new n(e++*e++),p,1),u=d.plus(r),u.d[w]!==void 0){for(s=w;u.d[s]===d.d[s]&&s--;);if(s==-1)break}s=d,d=r,r=u,u=s,h++}return Z=!0,u.d.length=w+1,u}function qe(n,e){for(var t=n;--e;)t*=n;return t}function wr(n,e){var t,r=e.s<0,i=ne(n,n.precision,1),s=i.times(.5);if(e=e.abs(),e.lte(s))return se=r?4:1,e;if(t=e.divToInt(i),t.isZero())se=r?3:2;else{if(e=e.minus(t.times(i)),e.lte(s))return se=ar(t)?r?2:3:r?4:1,e;se=ar(t)?r?1:4:r?3:2}return e.minus(i).abs()}function Si(n,e,t,r){var i,s,u,d,f,h,p,w,y,A=n.constructor,B=t!==void 0;if(B?(Jt(t,1,ce),r===void 0?r=A.rounding:Jt(r,0,8)):(t=A.precision,r=A.rounding),!n.isFinite())p=br(n);else{for(p=oe(n),u=p.indexOf("."),B?(i=2,e==16?t=t*4-3:e==8&&(t=t*3-2)):i=e,u>=0&&(p=p.replace(".",""),y=new A(1),y.e=p.length-u,y.d=Te(oe(y),10,i),y.e=y.d.length),w=Te(p,10,i),s=f=w.length;w[--f]==0;)w.pop();if(!w[0])p=B?"0p+0":"0";else{if(u<0?s--:(n=new A(n),n.d=w,n.e=s,n=nt(n,y,t,r,0,i),w=n.d,s=n.e,h=dr),u=w[t],d=i/2,h=h||w[t+1]!==void 0,h=r<4?(u!==void 0||h)&&(r===0||r===(n.s<0?3:2)):u>d||u===d&&(r===4||h||r===6&&w[t-1]&1||r===(n.s<0?8:7)),w.length=t,h)for(;++w[--t]>i-1;)w[t]=0,t||(++s,w.unshift(1));for(f=w.length;!w[f-1];--f);for(u=0,p="";u<f;u++)p+=yi.charAt(w[u]);if(B){if(f>1)if(e==16||e==8){for(u=e==16?4:3,--f;f%u;f++)p+="0";for(w=Te(p,i,e),f=w.length;!w[f-1];--f);for(u=1,p="1.";u<f;u++)p+=yi.charAt(w[u])}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=(e==16?"0x":e==2?"0b":e==8?"0o":"")+p}return n.s<0?"-"+p:p}function lr(n,e){if(n.length>e)return n.length=e,!0}function Kr(n){return new this(n).abs()}function $r(n){return new this(n).acos()}function zr(n){return new this(n).acosh()}function Gr(n,e){return new this(n).plus(e)}function Vr(n){return new this(n).asin()}function Xr(n){return new this(n).asinh()}function Jr(n){return new this(n).atan()}function Yr(n){return new this(n).atanh()}function tn(n,e){n=new this(n),e=new this(e);var t,r=this.precision,i=this.rounding,s=r+4;return!n.s||!e.s?t=new this(NaN):!n.d&&!e.d?(t=ne(this,s,1).times(e.s>0?.25:.75),t.s=n.s):!e.d||n.isZero()?(t=e.s<0?ne(this,r,i):new this(0),t.s=n.s):!n.d||e.isZero()?(t=ne(this,s,1).times(.5),t.s=n.s):e.s<0?(this.precision=s,this.rounding=1,t=this.atan(nt(n,e,s,1)),e=ne(this,s,1),this.precision=r,this.rounding=i,t=n.s<0?t.minus(e):t.plus(e)):t=this.atan(nt(n,e,s,1)),t}function en(n){return new this(n).cbrt()}function rn(n){return q(n=new this(n),n.e+1,2)}function nn(n,e,t){return new this(n).clamp(e,t)}function on(n){if(!n||typeof n!="object")throw Error(De+"Object expected");var e,t,r,i=n.defaults===!0,s=["precision",1,ce,"rounding",0,8,"toExpNeg",-_e,0,"toExpPos",0,_e,"maxE",0,_e,"minE",-_e,0,"modulo",0,9];for(e=0;e<s.length;e+=3)if(t=s[e],i&&(this[t]=Mi[t]),(r=n[t])!==void 0)if(Vt(r)===r&&r>=s[e+1]&&r<=s[e+2])this[t]=r;else throw Error(fe+t+": "+r);if(t="crypto",i&&(this[t]=Mi[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(cr);else this[t]=!1;else throw Error(fe+t+": "+r);return this}function sn(n){return new this(n).cos()}function an(n){return new this(n).cosh()}function vr(n){var e,t,r;function i(s){var u,d,f,h=this;if(!(h instanceof i))return new i(s);if(h.constructor=i,ur(s)){h.s=s.s,Z?!s.d||s.e>i.maxE?(h.e=NaN,h.d=null):s.e<i.minE?(h.e=0,h.d=[0]):(h.e=s.e,h.d=s.d.slice()):(h.e=s.e,h.d=s.d?s.d.slice():s.d);return}if(f=typeof s,f==="number"){if(s===0){h.s=1/s<0?-1:1,h.e=0,h.d=[0];return}if(s<0?(s=-s,h.s=-1):h.s=1,s===~~s&&s<1e7){for(u=0,d=s;d>=10;d/=10)u++;Z?u>i.maxE?(h.e=NaN,h.d=null):u<i.minE?(h.e=0,h.d=[0]):(h.e=u,h.d=[s]):(h.e=u,h.d=[s]);return}if(s*0!==0){s||(h.s=NaN),h.e=NaN,h.d=null;return}return xe(h,s.toString())}if(f==="string")return(d=s.charCodeAt(0))===45?(s=s.slice(1),h.s=-1):(d===43&&(s=s.slice(1)),h.s=1),pr.test(s)?xe(h,s):Hr(h,s);if(f==="bigint")return s<0?(s=-s,h.s=-1):h.s=1,xe(h,s.toString());throw Error(fe+s)}if(i.prototype=E,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.EUCLID=9,i.config=i.set=on,i.clone=vr,i.isDecimal=ur,i.abs=Kr,i.acos=$r,i.acosh=zr,i.add=Gr,i.asin=Vr,i.asinh=Xr,i.atan=Jr,i.atanh=Yr,i.atan2=tn,i.cbrt=en,i.ceil=rn,i.clamp=nn,i.cos=sn,i.cosh=an,i.div=ln,i.exp=un,i.floor=dn,i.hypot=fn,i.ln=cn,i.log=hn,i.log10=mn,i.log2=pn,i.max=_n,i.min=gn,i.mod=bn,i.mul=wn,i.pow=vn,i.random=yn,i.round=Mn,i.sign=Pn,i.sin=An,i.sinh=Sn,i.sqrt=Bn,i.sub=En,i.sum=In,i.tan=On,i.tanh=Cn,i.trunc=Tn,n===void 0&&(n={}),n&&n.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],e=0;e<r.length;)n.hasOwnProperty(t=r[e++])||(n[t]=this[t]);return i.config(n),i}function ln(n,e){return new this(n).div(e)}function un(n){return new this(n).exp()}function dn(n){return q(n=new this(n),n.e+1,3)}function fn(){var n,e,t=new this(0);for(Z=!1,n=0;n<arguments.length;)if(e=new this(arguments[n++]),e.d)t.d&&(t=t.plus(e.times(e)));else{if(e.s)return Z=!0,new this(1/0);t=e}return Z=!0,t.sqrt()}function ur(n){return n instanceof Me||n&&n.toStringTag===hr||!1}function cn(n){return new this(n).ln()}function hn(n,e){return new this(n).log(e)}function pn(n){return new this(n).log(2)}function mn(n){return new this(n).log(10)}function _n(){return gr(this,arguments,-1)}function gn(){return gr(this,arguments,1)}function bn(n,e){return new this(n).mod(e)}function wn(n,e){return new this(n).mul(e)}function vn(n,e){return new this(n).pow(e)}function yn(n){var e,t,r,i,s=0,u=new this(1),d=[];if(n===void 0?n=this.precision:Jt(n,1,ce),r=Math.ceil(n/W),this.crypto)if(crypto.getRandomValues)for(e=crypto.getRandomValues(new Uint32Array(r));s<r;)i=e[s],i>=429e7?e[s]=crypto.getRandomValues(new Uint32Array(1))[0]:d[s++]=i%1e7;else if(crypto.randomBytes){for(e=crypto.randomBytes(r*=4);s<r;)i=e[s]+(e[s+1]<<8)+(e[s+2]<<16)+((e[s+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(e,s):(d.push(i%1e7),s+=4);s=r/4}else throw Error(cr);else for(;s<r;)d[s++]=Math.random()*1e7|0;for(r=d[--s],n%=W,r&&n&&(i=Ht(10,W-n),d[s]=(r/i|0)*i);d[s]===0;s--)d.pop();if(s<0)t=0,d=[0];else{for(t=-1;d[0]===0;t-=W)d.shift();for(r=1,i=d[0];i>=10;i/=10)r++;r<W&&(t-=W-r)}return u.e=t,u.d=d,u}function Mn(n){return q(n=new this(n),n.e+1,this.rounding)}function Pn(n){return n=new this(n),n.d?n.d[0]?n.s:0*n.s:n.s||NaN}function An(n){return new this(n).sin()}function Sn(n){return new this(n).sinh()}function Bn(n){return new this(n).sqrt()}function En(n,e){return new this(n).sub(e)}function In(){var n=0,e=arguments,t=new this(e[n]);for(Z=!1;t.s&&++n<e.length;)t=t.plus(e[n]);return Z=!0,q(t,this.precision,this.rounding)}function On(n){return new this(n).tan()}function Cn(n){return new this(n).tanh()}function Tn(n){return q(n=new this(n),n.e+1,1)}E[Symbol.for("nodejs.util.inspect.custom")]=E.toString;E[Symbol.toStringTag]="Decimal";var Me=E.constructor=vr(Mi);ke=new Me(ke);Re=new Me(Re);var F=Me;var Le=(r=>(r[r.Spot=0]="Spot",r[r.Curve=1]="Curve",r[r.BidAsk=2]="BidAsk",r))(Le||{});var j=require("@cetusprotocol/common-sdk");var ae=1e3,xn=-443636,kn=443636,be=1e4,je=2e3,We=200,pe=443636n,Ue=1e8,Ze=1e9,te=1e4,Rn=604800,Fn=1747627200;var Y=bi(Ce());var Dn=new Y.default(524288),G=64,He=new Y.default(1).shln(G),yr=new Y.default(2).pow(new Y.default(128)).sub(new Y.default(1)),D=class n{static splitBinLiquidityInfo(e,t,r){let i=n.getPositionCount(t,r);if(i<=1)return[e];let s=[],u=t;for(let d=0;d<i;d++){let f=Math.min(u+1e3-2,r),h=e.bins.filter(p=>p.bin_id>=u&&p.bin_id<=f);s.push({bins:h,amount_a:h.reduce((p,w)=>(0,j.d)(p).plus(w.amount_a),(0,j.d)(0)).toFixed(0),amount_b:h.reduce((p,w)=>(0,j.d)(p).plus(w.amount_b),(0,j.d)(0)).toFixed(0)}),u=f+1}return s}static processBinsByRate(e,t){let r=[],i=(0,j.d)(0),s=(0,j.d)(0),u=!1;return e.forEach(d=>{let{amount_a:f,amount_b:h,liquidity:p="0"}=d,w=(0,j.d)(t).mul(p).toFixed(0),y=(0,j.d)(f).mul(t),A=(0,j.d)(h).mul(t);i=(0,j.d)(i).plus(y),s=(0,j.d)(s).plus(A),((0,j.d)(y).lt(1)&&(0,j.d)(y).gt(0)||(0,j.d)(A).lt(1)&&(0,j.d)(A).gt(0))&&(u=!0),r.push({bin_id:d.bin_id,amount_a:y.toFixed(0),amount_b:A.toFixed(0),price_per_lamport:d.price_per_lamport,liquidity:w})}),{bins:{bins:r,amount_a:i.toFixed(0),amount_b:s.toFixed(0)},has_invalid_amount:u}}static calculateOutByShare(e,t){let{amount_a:r,amount_b:i,liquidity:s="0"}=e;if(s==="0")return{amount_a:"0",amount_b:"0"};if((0,j.d)(t).gte((0,j.d)(s)))return{amount_a:r,amount_b:i};let u=(0,j.d)(t).div(s).mul(r).toFixed(0,F.ROUND_FLOOR),d=(0,j.d)(t).div(s).mul(i).toFixed(0,F.ROUND_FLOOR);return{amount_a:u,amount_b:d}}static getPositionCount(e,t){let i=(0,j.d)(t).sub(e).add(1).div(1e3);return Number(i.toFixed(0,F.ROUND_UP))}static getLiquidity(e,t,r){return(0,j.d)(r).mul(e).add((0,j.d)(t).mul((0,j.d)(2).pow(G))).toFixed(0)}static getAmountAFromLiquidity(e,t){return(0,j.d)(e).div((0,j.d)(t)).toFixed(0)}static getAmountBFromLiquidity(e){return(0,j.d)(e).div((0,j.d)(2).pow(G)).toFixed(0)}static getAmountsFromLiquidity(e,t,r,i){if((0,j.d)(i).isZero()&&K("LiquiditySupplyIsZero","Liquidity supply is zero"),(0,j.d)(r).gt((0,j.d)(i))&&K("InvalidDeltaLiquidity","Invalid delta liquidity"),(0,j.d)(r).isZero())return["0","0"];let s;(0,j.d)(e).isZero()?s="0":s=(0,j.d)(e).mul((0,j.d)(r)).div((0,j.d)(i)).toFixed(0,F.ROUND_FLOOR);let u;return(0,j.d)(t).isZero()?u="0":u=(0,j.d)(t).mul((0,j.d)(r)).div((0,j.d)(i)).toFixed(0,F.ROUND_FLOOR),[s,u]}static getPriceFromBinId(e,t,r,i){let s=n.getPricePerLamportFromBinId(e,t);return n.getPriceFromLamport(r,i,s).toString()}static getPricePerLamportFromBinId(e,t){let r=new F(t).div(new F(1e4));return new F(1).add(new F(r)).pow(new F(e)).toString()}static getBinIdFromPrice(e,t,r,i,s){let u=n.getPricePerLamport(i,s,e);return n.getBinIdFromLamportPrice(u,t,r)}static getBinIdFromLamportPrice(e,t,r){let i=new F(t).div(new F(1e4)),s=new F(e).log().dividedBy(new F(1).add(i).log());return(r?s.floor():s.ceil()).toNumber()}static getPricePerLamport(e,t,r){return new F(r).mul(new F(10**(t-e))).toString()}static getPriceFromLamport(e,t,r){return new F(r).div(new F(10**(t-e))).toString()}static getReversePrice(e){return new F(1).div(e).toString()}static getQPriceFromId(e,t){let r=new Y.default(t).shln(G).div(new Y.default(1e4)),i=He.add(r);return n.pow(i,new Y.default(e)).toString()}static getPricePerLamportFromQPrice(e){return j.MathUtil.fromX64(new Y.default(e)).toString()}static pow(e,t){let r=t.isNeg();if(t.isZero())return He;if(t=r?t.abs():t,t.gt(Dn))return new Y.default(0);let i=e,s=He;return i.gte(s)&&(i=yr.div(i),r=!r),t.and(new Y.default(1)).isZero()||(s=s.mul(i).shrn(G)),i=i.mul(i).shrn(G),t.and(new Y.default(2)).isZero()||(s=s.mul(i).shrn(G)),i=i.mul(i).shrn(G),t.and(new Y.default(4)).isZero()||(s=s.mul(i).shrn(G)),i=i.mul(i).shrn(G),t.and(new Y.default(8)).isZero()||(s=s.mul(i).shrn(G)),i=i.mul(i).shrn(G),t.and(new Y.default(16)).isZero()||(s=s.mul(i).shrn(G)),i=i.mul(i).shrn(G),t.and(new Y.default(32)).isZero()||(s=s.mul(i).shrn(G)),i=i.mul(i).shrn(G),t.and(new Y.default(64)).isZero()||(s=s.mul(i).shrn(G)),i=i.mul(i).shrn(G),t.and(new Y.default(128)).isZero()||(s=s.mul(i).shrn(G)),i=i.mul(i).shrn(G),t.and(new Y.default(256)).isZero()||(s=s.mul(i).shrn(G)),i=i.mul(i).shrn(G),t.and(new Y.default(512)).isZero()||(s=s.mul(i).shrn(G)),i=i.mul(i).shrn(G),t.and(new Y.default(1024)).isZero()||(s=s.mul(i).shrn(G)),i=i.mul(i).shrn(G),t.and(new Y.default(2048)).isZero()||(s=s.mul(i).shrn(G)),i=i.mul(i).shrn(G),t.and(new Y.default(4096)).isZero()||(s=s.mul(i).shrn(G)),i=i.mul(i).shrn(G),t.and(new Y.default(8192)).isZero()||(s=s.mul(i).shrn(G)),i=i.mul(i).shrn(G),t.and(new Y.default(16384)).isZero()||(s=s.mul(i).shrn(G)),i=i.mul(i).shrn(G),t.and(new Y.default(32768)).isZero()||(s=s.mul(i).shrn(G)),i=i.mul(i).shrn(G),t.and(new Y.default(65536)).isZero()||(s=s.mul(i).shrn(G)),i=i.mul(i).shrn(G),t.and(new Y.default(131072)).isZero()||(s=s.mul(i).shrn(G)),i=i.mul(i).shrn(G),t.and(new Y.default(262144)).isZero()||(s=s.mul(i).shrn(G)),s.isZero()?new Y.default(0):(r&&(s=yr.div(s)),s)}static binScore(e){let t=BigInt(e)+pe;return(t<0n||t>pe*2n)&&K("InvalidBinId",new Error("Invalid bin ID"),{[j.DETAILS_KEYS.METHOD_NAME]:"binScore",[j.DETAILS_KEYS.REQUEST_PARAMS]:{binId:e}}),t.toString()}static scoreToBinId(e){let t=BigInt(e)-pe;return(t<-pe||t>pe)&&K("InvalidBinId",new Error("Invalid score"),{[j.DETAILS_KEYS.METHOD_NAME]:"scoreToBinId",[j.DETAILS_KEYS.REQUEST_PARAMS]:{score:e}}),Number(t)}static resolveBinPosition(e){let t=BigInt(e),r=t>>4n,i=Number(t&0xfn);return[r.toString(),i]}static findMinMaxBinId(e){let t=1+e/1e4,i=new F("18446744073709551615").log(10).div(new F(t).log(10)).floor(),s=i.neg(),u=i,d=(0,j.d)(1),f=(0,j.d)("340282366920938463463374607431768211455");for(;;){let h=(0,j.d)(n.getQPriceFromId(s.toNumber(),e));if(h.gt(d)&&!h.isZero())break;s=s.add(1)}for(;;){let h=(0,j.d)(n.getQPriceFromId(u.toNumber(),e));if(h.lt(f)&&!h.isZero())break;u=u.sub(1)}return{minBinId:s.toNumber(),maxBinId:u.toNumber()}}static getBinShift(e,t,r){let i=n.getPricePerLamportFromBinId(e,t),s=(0,j.d)(i).mul(1+r).toString(),u=n.getBinIdFromLamportPrice(s,t,!0),d=(0,j.d)(u).sub(e).abs().toFixed(0,F.ROUND_UP);return console.log("getBinShift Options:",{active_id:e,bin_shift:d}),Number(d)}};var Yt=require("@mysten/sui/bcs");function Bi(n){try{let e=n.parsedJson;return{id:e.pool_id,bin_step:Number(e.bin_step),coin_type_a:(0,$.fixCoinType)(e.coin_type_a,!1),coin_type_b:(0,$.fixCoinType)(e.coin_type_b,!1)}}catch(e){return K("ParseError",e,{[$.DETAILS_KEYS.METHOD_NAME]:"parseDlmmBasePool",[$.DETAILS_KEYS.REQUEST_PARAMS]:n})}}function Pe(n){try{let e=(0,$.getObjectFields)(n),t=(0,$.getObjectType)(n),r=(0,$.extractStructTagFromType)(t),i={bin_step:e.bin_manager.fields.bin_step,bin_manager_handle:e.bin_manager.fields.bins.fields.id.id,size:e.bin_manager.fields.bins.fields.size},s={bin_step:e.position_manager.fields.bin_step,position_index:e.position_manager.fields.position_index,position_handle:e.position_manager.fields.positions.fields.id.id,size:e.position_manager.fields.positions.fields.size},u=e.reward_manager.fields,d=u.rewards.map(w=>{let y=w.fields.current_emission_rate,A=$.MathUtil.fromX64(new Mr.default(y)),B=Math.floor(A.toNumber()*60*60*24).toString();return{reward_coin:(0,$.fixCoinType)(w.fields.reward_coin.fields.name,!1),emissions_per_second:A.toString(),emissions_per_day:B,period_emission_rates:{id:w.fields.period_emission_rates.fields.id.id,size:w.fields.period_emission_rates.fields.size}}}),f={is_public:u.is_public,emergency_reward_pause:u.emergency_reward_pause,vault:{id:u.vault.fields.id.id,size:u.vault.fields.size},rewards:d,last_updated_time:u.last_updated_time},h={volatility_accumulator:e.v_parameters.fields.volatility_accumulator,volatility_reference:e.v_parameters.fields.volatility_reference,index_reference:(0,$.asIntN)(BigInt(e.v_parameters.fields.index_reference.fields.bits)),last_update_timestamp:e.v_parameters.fields.last_update_timestamp,bin_step_config:e.v_parameters.fields.bin_step_config.fields},p={id:e.id.id,bin_step:Number(e.bin_step),coin_type_a:(0,$.fixCoinType)(r.type_arguments[0],!1),coin_type_b:(0,$.fixCoinType)(r.type_arguments[1],!1),pool_type:t,index:Number(e.index),bin_manager:i,variable_parameters:h,active_id:(0,$.asIntN)(BigInt(e.active_id.fields.bits)),permissions:e.permissions.fields,balance_a:e.balance_a,balance_b:e.balance_b,base_fee_rate:e.base_fee_rate,protocol_fee_a:e.protocol_fee_a,protocol_fee_b:e.protocol_fee_b,url:e.url,reward_manager:f,position_manager:s};return p.bin_step=p.bin_manager.bin_step,p}catch(e){return console.log("\u{1F680} ~ parseDlmmPool ~ error:",e),K("ParseError",e,{[$.DETAILS_KEYS.METHOD_NAME]:"parseDlmmPool",[$.DETAILS_KEYS.REQUEST_PARAMS]:n})}}function Qe(n){let e=(0,$.getObjectFields)(n),t=(0,$.getObjectType)(n),r=(0,$.extractStructTagFromType)(t);return{id:e.id.id,name:e.name,ref_fee_rate:(0,$.d)(e.ref_fee_rate).div(1e4).toNumber(),start_time:Number(e.start_time),end_time:Number(e.end_time),balances:{id:e.balances.fields.id.id,size:e.balances.fields.size},type:r.full_address}}function Ke(n){try{let e=(0,$.getObjectFields)(n);return{uri:e.uri,index:e.index,id:e.id.id,name:e.name,pool_id:e.pool_id,lower_bin_id:(0,$.asIntN)(BigInt(e.lower_bin_id.fields.bits)),upper_bin_id:(0,$.asIntN)(BigInt(e.upper_bin_id.fields.bits)),liquidity_shares:e.liquidity_shares,description:e.description,coin_type_a:(0,$.fixCoinType)(e.coin_type_a,!1),coin_type_b:(0,$.fixCoinType)(e.coin_type_b,!1)}}catch(e){return console.log("\u{1F680} ~ parseDlmmPosition ~ error:",e),K("ParseError",e,{[$.DETAILS_KEYS.METHOD_NAME]:"parseDlmmPosition",[$.DETAILS_KEYS.REQUEST_PARAMS]:n})}}function Nn(n,e,t,r){let i=n.map((d,f)=>{let h=t+f,p=D.getPricePerLamportFromBinId(h,e);if(h===r.bin_id){let{amount_a:A,amount_b:B}=D.calculateOutByShare(r,d);return{bin_id:h,amount_a:A,amount_b:B,liquidity:d,price_per_lamport:p}}if(h<r.bin_id){let A=D.getAmountBFromLiquidity(d);return{bin_id:h,amount_a:"0",amount_b:A,liquidity:d,price_per_lamport:p}}let w=D.getQPriceFromId(h,e),y=D.getAmountAFromLiquidity(d,w);return{bin_id:h,amount_a:y,amount_b:"0",liquidity:d,price_per_lamport:p}}),s=i.reduce((d,f)=>d.add(new F(f.amount_a)),new F(0)).toFixed(0),u=i.reduce((d,f)=>d.add(new F(f.amount_b)),new F(0)).toFixed(0);return{bins:i,amount_a:s,amount_b:u}}function Ei(n){try{let e=Yt.bcs.struct("BinAmount",{id:Yt.bcs.struct("I32",{bits:Yt.bcs.u32()}),amount_a:Yt.bcs.u64(),amount_b:Yt.bcs.u64(),price:Yt.bcs.u128(),liquidity_supply:Yt.bcs.u128(),rewards_growth_global:Yt.bcs.vector(Yt.bcs.u128()),fee_a_growth_global:Yt.bcs.u128(),fee_b_growth_global:Yt.bcs.u128()});return Yt.bcs.vector(e).parse(Uint8Array.from(n.results[0].returnValues[0][0])).map(r=>({bin_id:(0,$.asIntN)(BigInt(r.id.bits)),amount_a:r.amount_a,amount_b:r.amount_b,liquidity:r.liquidity_supply,price_per_lamport:D.getPricePerLamportFromQPrice(r.price)}))}catch(e){return console.log("\u{1F680} ~ parseBinInfo ~ error:",e),[]}}function Ii(n){try{return{bin_id:(0,$.asIntN)(BigInt(n.id.fields.bits)),amount_a:n.amount_a,amount_b:n.amount_b,liquidity:n.liquidity_supply,price_per_lamport:D.getPricePerLamportFromQPrice(n.price)}}catch(e){return console.log("\u{1F680} ~ parseBinInfo ~ error:",e),K("ParseError",e,{[$.DETAILS_KEYS.METHOD_NAME]:"parseBinInfo",[$.DETAILS_KEYS.REQUEST_PARAMS]:{fields:n}})}}function Oi(n){let e={},t=n.events?.filter(r=>r.type.includes("pool::CollectFeeEvent"));for(let r=0;r<t.length;r+=1){let{parsedJson:i}=t[r],s={position_id:i.position,fee_owned_a:i.fee_a,fee_owned_b:i.fee_b};e[i.position]=s}return e}function Ci(n){let e={},t=n.events?.filter(r=>r.type.includes("pool::CollectRewardEvent"));for(let r=0;r<t.length;r+=1){let{parsedJson:i}=t[r],s=i.position,u=i.reward,d=i.amount,f={coin_type:(0,$.fixCoinType)(u.name,!1),reward_owned:d},h=e[s];h?h.rewards.push(f):h={position_id:s,rewards:[f]},e[s]=h}return e}function Ti(n,e){let t=n.events?.filter(r=>r.type.includes("pool::SwapEvent"));for(let r=0;r<t.length;r+=1){let{parsedJson:i}=t[r],{partner:s,pool:u,amount_in:d,amount_out:f,fee:h,ref_fee:p,bin_swaps:w,from:y,target:A}=i,B=w.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:u,a2b:e,in_amount:d,out_amount:f,ref_fee_amount:p,fee_amount:h,bin_swaps:B,partner:s,from_coin_type:(0,$.fixCoinType)(y.name,!1),to_coin_type:(0,$.fixCoinType)(A.name,!1)}}}function qn(n){switch(n){case 0:return 0;case 1:return 1;case 2:return 2}}var Pr=["RemoveLiquidityEvent","SwapEvent","AddLiquidityEvent","ClosePositionEvent"];function xi(n,e,t,r){let i=[],{timestampMs:s,events:u}=n;return u?.forEach((d,f)=>{let{name:h,address:p}=(0,$.extractStructTagFromType)(d.type);if(Pr.includes(h)&&p===t&&r===d.parsedJson.pool){let w={tx:d.id.txDigest,sender:d.sender,type:d.type,block_time:s||"0",index:`${e}_${f}`,parsed_json:d.parsedJson};i.push(w)}}),i}function Ln(n,e,t){let r=[],i=0,s=new Date(n*1e3).getTime(),u=new Date().getTime();for(;;){let d=s+i*t;if(d>=u&&r.push(d),i>=e)break;i+=1}return r}function jn(n,e,t,r){let i=[];for(let s=e;s<=t;s+=r){let u=n.findLast(d=>(0,$.d)(s).gte(d.time));u?i.push({time:s.toString(),emissions_per_second:u.emissions_per_second,emissions_per_day:u.emissions_per_day,visualized_time:new Date(s*1e3).toLocaleString()}):i.push({emissions_per_day:"0",time:s.toString(),emissions_per_second:"0",visualized_time:new Date(s*1e3).toLocaleString()})}return i}function Wn(n){if(n.length===0)return;let e=new Date().getTime()/1e3,t=n.findLast(r=>(0,$.d)(e).gte(r.time));return t||n[n.length-1]}function re(n,e){let t=n.mul(e);if(t.gt(0)&&t.lt(1))throw new me(`Multiplication ${t} is less than 1`,"AmountTooSmall");return t.floor()}function ki(n){switch(n){case 0:return"spot";case 1:return"curve";case 2:return"bid_ask"}}var et=require("@cetusprotocol/common-sdk");var Xt=class n{static toWeightSpotBalanced(e,t){let r=[];for(let i=e;i<=t;i++)r.push({bin_id:i,weight:1});return r}static toWeightDescendingOrder(e,t){let r=[];for(let i=e;i<=t;i++)r.push({bin_id:i,weight:t-i+1});return r}static toWeightAscendingOrder(e,t){let r=[];for(let i=e;i<=t;i++)r.push({bin_id:i,weight:i-e+1});return r}static toWeightCurve(e,t,r){if(r<e)return n.toWeightDescendingOrder(e,t);if(r>t)return n.toWeightAscendingOrder(e,t);let i=2e3,u=i-200,d=r>e?Math.floor(u/(r-e)):0,f=t>r?Math.floor(u/(t-r)):0,h=[];for(let p=e;p<=t;p++)p<r?h.push({bin_id:p,weight:i-(r-p)*d}):p>r?h.push({bin_id:p,weight:i-(p-r)*f}):h.push({bin_id:p,weight:i});return h}static toWeightBidAsk(e,t,r){if(r>t)return n.toWeightDescendingOrder(e,t);if(r<e)return n.toWeightAscendingOrder(e,t);let i=2e3,s=200,u=i-s,d=r>e?Math.floor(u/(r-e)):0,f=t>r?Math.floor(u/(t-r)):0,h=[];for(let p=e;p<=t;p++)p<r?h.push({bin_id:p,weight:s+(r-p)*d}):p>r?h.push({bin_id:p,weight:s+(p-r)*f}):h.push({bin_id:p,weight:s});return h}static toAmountBidSide(e,t,r,i,s=!1){let u=i.filter(f=>f.bin_id<=e).reduce(function(f,h){return s?h.bin_id>e?f:f.add(h.weight):h.bin_id>=e?f:f.add(h.weight)},(0,et.d)(0));if(u.cmp((0,et.d)(0))!=1)throw Error("Invalid parameters");return{bins:i.map(f=>{let h=D.getPricePerLamportFromBinId(f.bin_id,r);if(!(f.bin_id<=e)||f.bin_id>=e&&!s)return{bin_id:f.bin_id,amount_a:"0",amount_b:"0",price_per_lamport:h,liquidity:"0"};{let w=(0,et.d)(f.weight).div(u),y=re((0,et.d)(t),w).toString(),A="0",B=D.getQPriceFromId(f.bin_id,r),S=D.getLiquidity(A,y,B);return{bin_id:f.bin_id,amount_b:y,amount_a:A,price_per_lamport:h,liquidity:S}}}),amount_a:"0",amount_b:t}}static toAmountAskSide(e,t,r,i,s=!1){let u=i.filter(f=>f.bin_id>=e).reduce(function(f,h){if(h.bin_id<=e&&!s)return f;{let p=D.getPricePerLamportFromBinId(h.bin_id,t),w=new F(h.weight).div(p);return f.add(w)}},new F(0));if(u.cmp(new F(0))!=1)throw Error("Invalid parameters");return{bins:i.map(f=>{let h=D.getPricePerLamportFromBinId(f.bin_id,t);if(!(f.bin_id>=e)||f.bin_id<=e&&!s)return{bin_id:f.bin_id,amount_a:"0",amount_b:"0",price_per_lamport:h,liquidity:"0"};{let y=new F(f.weight).div(h).div(u),A=re((0,et.d)(r),y).toString(),B="0",S=D.getQPriceFromId(f.bin_id,t),T=D.getLiquidity(A,B,S);return{bin_id:f.bin_id,amount_a:A,amount_b:B,price_per_lamport:h,liquidity:T}}}),amount_a:r,amount_b:"0"}}static toAmountBothSide(e,t,r,i,s,u,d){let f=!(0,et.d)(r).isZero()&&(0,et.d)(i).isZero(),h=(0,et.d)(r).isZero()&&!(0,et.d)(i).isZero();if(e>d[d.length-1].bin_id)return n.toAmountBidSide(e,i,t,d);if(h&&e!==d[d.length-1].bin_id)return n.toAmountBidSide(e,i,t,d,!0);if(e<d[0].bin_id)return n.toAmountAskSide(e,t,r,d);if(f&&e!==d[0].bin_id)return n.toAmountAskSide(e,t,r,d,!0);let p=d.filter(w=>w.bin_id===e);if(p.length===1){let{totalWeightA:w,totalWeightB:y,activeWeightA:A,activeWeightB:B}=n.calculateTotalWeights(t,d,e,p[0],s,u,f?"a":h?"b":void 0),S=new F(r.toString()).div(w),T=new F(i.toString()).div(y),x=d.map(C=>{let z=D.getPricePerLamportFromBinId(C.bin_id,t);if(C.bin_id<e||C.bin_id===e&&h){let rt=re(T,new F(C.weight)),v="0",o=D.getQPriceFromId(C.bin_id,t),l=D.getLiquidity(v,rt.toString(),o);return{bin_id:C.bin_id,amount_a:"0",amount_b:rt.toString(),price_per_lamport:z,liquidity:l}}if(C.bin_id>e||C.bin_id===e&&f){let rt=new F(C.weight).div(z),v=re(S,new F(rt)),o="0",l=D.getQPriceFromId(C.bin_id,t),c=D.getLiquidity(v.toString(),o,l);return{bin_id:C.bin_id,amount_a:v.toString(),amount_b:"0",price_per_lamport:z,liquidity:c}}let Q=re(S,A),it=re(T,B),at=Q.toString(),Kt=it.toString(),$t=D.getQPriceFromId(C.bin_id,t),H=D.getLiquidity(at,Kt,$t);return{bin_id:C.bin_id,amount_a:at,amount_b:Kt,price_per_lamport:z,liquidity:H}}),k=x.reduce((C,z)=>(0,et.d)(C).add((0,et.d)(z.amount_a)),(0,et.d)(0)).toString(),I=x.reduce((C,z)=>(0,et.d)(C).add((0,et.d)(z.amount_b)),(0,et.d)(0)).toString();return{bins:x,amount_a:k,amount_b:I}}else{let{totalWeightA:w,totalWeightB:y}=n.calculateTotalWeights(t,d,e),A=new F(r.toString()).div(w),B=new F(i.toString()).div(y),S=d.map(k=>{let I=D.getPricePerLamportFromBinId(k.bin_id,t);if(k.bin_id<e){let C=re(B,new F(k.weight));return{bin_id:k.bin_id,amount_a:"0",amount_b:C.toString(),price_per_lamport:I}}else{let C=new F(k.weight).div(I),z=re(A,C);return{bin_id:k.bin_id,amount_a:z.toString(),amount_b:"0",price_per_lamport:I}}}),T=S.reduce((k,I)=>(0,et.d)(k).add((0,et.d)(I.amount_a)),(0,et.d)(0)).toString(),x=S.reduce((k,I)=>(0,et.d)(k).add((0,et.d)(I.amount_b)),(0,et.d)(0)).toString();return{bins:S,amount_a:T,amount_b:x}}}static autoFillCoinByWeight(e,t,r,i,s,u,d){if(e>d[d.length-1].bin_id)return n.toAmountBidSide(e,r,t,d);if(e<d[0].bin_id)return n.toAmountAskSide(e,t,r,d);let f=d.filter(A=>A.bin_id===e),{totalWeightA:h,totalWeightB:p}=n.calculateTotalWeights(t,d,e,f.length===1?f[0]:void 0,f.length===1?s:void 0,f.length===1?u:void 0),w=(0,et.d)(0);i?w=h.isZero()?new F(1):new F(r).div(h):w=p.isZero()?new F(1):new F(r).div(p);let y=re(w,i?p:h).toString();return n.toAmountBothSide(e,t,i?r:y,i?y:r,s,u,d)}static calculateTotalWeights(e,t,r,i,s,u,d){let f=(0,et.d)(D.getPricePerLamportFromBinId(r,e)),h=(0,et.d)(0),p=(0,et.d)(0);if(s&&u&&i&&!d)if((0,et.d)(s).isZero()&&(0,et.d)(u).isZero())h=new F(i.weight).div(f.mul(new F(2))),p=new F(i.weight).div(new F(2));else{let A=new F(s.toString()),B=new F(u.toString());(0,et.d)(s).isZero()||(h=new F(i.weight).div(f.add(B.div(A)))),(0,et.d)(u).isZero()||(p=new F(i.weight).div(new F(1).add(f.mul(A).div(B))))}let w=h,y=p;return t.forEach(A=>{if((A.bin_id<r||d==="b")&&(y=y.add(new F(A.weight))),A.bin_id>r||d==="a"){let B=D.getPricePerLamportFromBinId(A.bin_id,e),S=new F(A.weight).div(B);w=w.add(S)}}),{totalWeightA:w,totalWeightB:y,activeWeightA:h,activeWeightB:p}}};var ve=class{static toAmountsBothSideByStrategy(e,t,r,i,s,u,d,f,h){switch(h){case 0:{let p=Xt.toWeightSpotBalanced(r,i);return Xt.toAmountBothSide(e,t,s,u,d,f,p)}case 1:{let p=Xt.toWeightCurve(r,i,e);return Xt.toAmountBothSide(e,t,s,u,d,f,p)}case 2:{let p=Xt.toWeightBidAsk(r,i,e);return Xt.toAmountBothSide(e,t,s,u,d,f,p)}}}static autoFillCoinByStrategy(e,t,r,i,s,u,d,f,h){switch(h){case 0:{let p=Xt.toWeightSpotBalanced(d,f);return Xt.autoFillCoinByWeight(e,t,r,i,s,u,p)}case 1:{let p=Xt.toWeightCurve(d,f,e);return Xt.autoFillCoinByWeight(e,t,r,i,s,u,p)}case 2:{let p=Xt.toWeightBidAsk(d,f,e);return Xt.autoFillCoinByWeight(e,t,r,i,s,u,p)}}}};var Qt=require("@cetusprotocol/common-sdk");var Ri=class n{static getVariableFee(e){let{volatility_accumulator:t,bin_step_config:r}=e,{variable_fee_control:i,bin_step:s}=r;return(0,Qt.d)(i).gt(0)?(0,Qt.d)(t).mul(s).pow(2).mul(i).add(99999999999).div(1e11).toFixed(0):"0"}static calculateCompositionFee(e,t){let r=(0,Qt.d)(e).mul(t);return(0,Qt.d)(r).mul((0,Qt.d)(1e9).add(t)).div((0,Qt.d)(1e9).pow(2)).toFixed(0)}static calculateProtocolFee(e,t){return(0,Qt.d)(e).mul(t).div(1e4).ceil().toFixed(0)}static getProtocolFees(e,t,r){let i=n.calculateProtocolFee(e,r),s=n.calculateProtocolFee(t,r);return{protocol_fee_a:i,protocol_fee_b:s}}static getCompositionFees(e,t,r,i){if((0,Qt.d)(e.liquidity||"0").eq((0,Qt.d)(0)))return{fees_a:"0",fees_b:"0"};let{bin_step:s,base_factor:u}=r,d=D.getQPriceFromId(e.bin_id,s),f=D.getLiquidity(t.amount_a,t.amount_b,d),{amount_a:h,amount_b:p}=D.calculateOutByShare({bin_id:e.bin_id,liquidity:(0,Qt.d)(e.liquidity).add(f).toFixed(0),amount_a:(0,Qt.d)(e.amount_a).add(t.amount_a).toFixed(0),amount_b:(0,Qt.d)(e.amount_b).add(t.amount_b).toFixed(0),price_per_lamport:e.price_per_lamport},f),w=(0,Qt.d)(s).mul(u),y=n.getVariableFee(i),A=(0,Qt.d)(w).add(y).toFixed(0);(0,Qt.d)(A).gt(1e8)&&(A=1e8.toString());let B="0",S="0";return(0,Qt.d)(h).gt(t.amount_a)&&(B=n.calculateCompositionFee(h,A)),(0,Qt.d)(p).gt(t.amount_b)&&(S=n.calculateCompositionFee(p,A)),{fees_a:B,fees_b:S}}};var U=require("@cetusprotocol/common-sdk");var Fi=class{static calculateIlm(e){let{curvature:t,initial_price:r,max_price:i,bin_step:s,total_supply:u,pool_share_percentage:d,config:f}=e,{price_curve_points_num:h,liquidity_distribution_num:p,tokens_table_num:w,price_table_num:y}=f;if((0,U.d)(d).lt(0)||(0,U.d)(d).gt(100))throw new Error("Pool Share Percentage must be greater than 0 and less than 100.");let A=!1;if((0,U.d)(i).lt((0,U.d)(r)))throw new Error("Maximum Price must be greater or equal to Initial Price.");if((0,U.d)(i).eq(r)&&!(0,U.d)(t).eq(0))throw new Error("Curvature must be 0 when Maximum and Initial Price are equal.");if(!(0,U.d)(i).eq(r)&&(0,U.d)(t).eq(0))throw new Error("Maximum and Initial Price must be equal when Curvature is 0.");(0,U.d)(i).eq(r)&&(0,U.d)(t).eq(0)&&(A=!0);let B=_=>(0,U.d)(C).mul((0,U.d)(_).div(I).pow(t)).add((0,U.d)(r)).toString(),S=(_,a)=>{let b=(0,U.d)(C).mul((0,U.d)(I).pow(-t)).mul((0,U.d)(_).pow(t+1)).div(t+1).add((0,U.d)(r).mul(_)),R=(0,U.d)(C).mul((0,U.d)(I).pow(-t)).mul((0,U.d)(a).pow(t+1)).div(t+1).add((0,U.d)(r).mul(a));return b.sub(R)},T=_=>(0,U.d)(I).mul((0,U.d)(_).sub(r).div(C).pow(1/t)).toString(),x=_=>(0,U.d)(I).mul((0,U.d)(_).sub(r).pow(1/t-1)).div((0,U.d)(t).mul((0,U.d)(C).pow(1/t))).toString(),k=_=>(0,U.d)(_).sub(r).div(C).pow(1/t).mul(I),I=(0,U.d)(u).mul(d).div(100),C=(0,U.d)(i).sub((0,U.d)(r)).toFixed(8),z=[],Q=[],it=D.getBinIdFromLamportPrice(r,s,!1),at=D.getBinIdFromLamportPrice(i,s,!1),Kt=(0,U.d)(0),$t=it;if(A)z.push(r),Q.push((0,U.d)(r).mul(I).toString());else for(;$t<=at;){let _=D.getPricePerLamportFromBinId($t,s),a=D.getPricePerLamportFromBinId($t+1,s),b=k(a).sub(k(_));Kt=Kt.add(b),Q.push((0,U.d)(b).mul(_).toString()),z.push(_),$t++}let H={price_curve:[],liquidity_curve:[],dlmm_bins:[],tokens_table:[],price_table:[]};var rt=(0,U.d)(C).div(100);let v=[];for(let _=0;_<h;_++){let a=(0,U.d)(_).mul(I).div(h-1).toString(),b=A?i:B(a);v.push({x:a,y:b})}H.price_curve=v;let o=[];if(A)o=[{x:r,y:"0"},{x:r,y:(0,U.d)(I).div(2).toString()},{x:r,y:I.toString()}];else for(let _=0;_<p;_++){let a=(0,U.d)(r).add((0,U.d)(_).mul((0,U.d)(rt))).toFixed(9),b=x(a);o.push({x:a,y:b})}H.liquidity_curve=o;let l=[];z.forEach((_,a)=>{let b=_,R=Q[a];l.push({x:b,y:R})}),H.dlmm_bins=l;let c=[],m=(0,U.d)(0),g=(0,U.d)(I).div(w).toFixed(5);for(;m.lte(I);){let _=(0,U.d)(B(m.toString())).toFixed(8),a=m.toFixed(8),b=S(Number(a),0);c.push({withdrawn:a,price:_,usdc_in_pool:b.toString()}),m=m.add(g)}H.tokens_table=c;let M=(0,U.d)(C).mul(1e10).floor().div(1e11),P=[];if(A)P.push({withdrawn:I.toString(),price:r,usdc_in_pool:(0,U.d)(I).mul(r).toString()});else{let _=(0,U.d)(0),a=(0,U.d)(r);for(;_.lte(y);){let b=(0,U.d)(T(a.toFixed(8))).toFixed(8),R=S(Number(b),0).toFixed(8);P.push({withdrawn:b,price:a.toFixed(8),usdc_in_pool:R}),a=(0,U.d)(a).add(M),_=_.add((0,U.d)(1))}}return H.price_table=P,H}};var Ar=require("@mysten/sui/client"),Di=require("@mysten/sui/utils"),Se=require("@mysten/sui/bcs"),Be=class{constructor(e){this._sdk=e}get sdk(){return this._sdk}async getBasePoolList(e="all",t=!1){let{dlmm_pool:r}=this._sdk.sdkOptions,i={data:[],has_next_page:!1},s=e==="all",u=`${r.package_id}_getBasePoolList`;if(s){let d=this._sdk.getCache(u,t);if(d&&d.length>0)return i.data.push(...d),i}try{let d=`${r.package_id}::registry::CreatePoolEvent`,f=await this._sdk.FullClient.queryEventsByPage({MoveEventType:d},e);i.has_next_page=f.has_next_page,i.next_cursor=f.next_cursor,f.data.forEach(h=>{let p=Bi(h);i.data.push(p)}),s&&this._sdk.updateCache(`${r.package_id}_getPoolImmutables`,i.data)}catch(d){return K("FetchError",d,{[X.DETAILS_KEYS.METHOD_NAME]:"getBasePoolList"})}return i}async getPools(e="all",t=!1){let r={data:[],has_next_page:!1},i=await this.getBasePoolList(e,t);if(i.data.length===0)return r;try{let s=await this._sdk.FullClient.batchGetObjects(i.data.map(u=>u.id),{showContent:!0,showType:!0});r.has_next_page=i.has_next_page,r.next_cursor=i.next_cursor;for(let u of s){let d=Pe(u),f=`${d.id}_getDlmmPool`;this._sdk.updateCache(f,d),r.data.push(d)}}catch(s){return K("FetchError",s,{[X.DETAILS_KEYS.METHOD_NAME]:"getPools"})}return r}async getBinInfo(e,t,r,i=!0){try{let s=`${e}_getBinInfo_${t}`,u=this._sdk.getCache(s,i);if(u!==void 0)return u;let d=D.binScore(t),[f,h]=D.resolveBinPosition(d),w=(await this._sdk.FullClient.getDynamicFieldObject({parentId:e,name:{type:"u64",value:f}})).data.content.fields.value.fields.value.fields.group.fields.bins[h].fields,y=Ii(w);return this._sdk.updateCache(s,y),y}catch{return{bin_id:t,amount_a:"0",amount_b:"0",liquidity:"0",price_per_lamport:D.getPricePerLamportFromBinId(t,r)}}}async getTotalFeeRate(e){let{dlmm_pool:t}=this._sdk.sdkOptions,{pool_id:r,coin_type_a:i,coin_type_b:s}=e,u=new Ae.Transaction;u.moveCall({target:`${t.published_at}::pool::get_total_fee_rate`,arguments:[u.object(r)],typeArguments:[i,s]});let d=await this._sdk.FullClient.devInspectTransactionBlock({transactionBlock:u,sender:(0,Di.normalizeSuiAddress)("0x0")});return Se.bcs.struct("FeeRate",{base_fee_rate:Se.bcs.u64(),var_fee_rate:Se.bcs.u64(),total_fee_rate:Se.bcs.u64()}).parse(Uint8Array.from(d.results[0].returnValues[0][0]))}async getPoolBinInfo(e){let{dlmm_pool:t}=this._sdk.sdkOptions,{pool_id:r,coin_type_a:i,coin_type_b:s}=e,u=1e3,d=[],f,h=!0;for(;h;){let p=new Ae.Transaction;p.moveCall({target:`${t.published_at}::pool::fetch_bins`,arguments:[p.object(r),p.pure.vector("u32",f?[Number((0,X.asUintN)(BigInt(f)))]:[]),p.pure.u64(u)],typeArguments:[i,s]});let w=await this._sdk.FullClient.devInspectTransactionBlock({transactionBlock:p,sender:(0,Di.normalizeSuiAddress)("0x0")}),y=Ei(w);d.push(...y),f=y.length>0?y[y.length-1].bin_id:void 0,h=y.length===u}return d.sort((p,w)=>p.bin_id-w.bin_id)}async getPoolTransactionList({pool_id:e,pagination_args:t,order:r="descending",full_rpc_url:i}){let{FullClient:s,sdkOptions:u}=this._sdk,d;i?d=(0,X.createFullClient)(new Ar.SuiClient({url:i})):d=s;let f={data:[],has_next_page:!1},h=50,p=t,w=t.limit||10;do{let y=await d.queryTransactionBlocksByPage({ChangedObject:e},{...p,limit:50},r);y.data.forEach((A,B)=>{let S=xi(A,B,u.dlmm_pool.package_id,e);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<w&&f.has_next_page);return f.data.length>w&&(f.data=f.data.slice(0,w),f.has_next_page=!0),f.data.length>0&&(f.next_cursor=f.data[f.data.length-1].tx),f}async getRangeBinInfo(e,t,r,i){let s=[];for(let u=t;u<=r;u++){let d=await Promise.all([this.getBinInfo(e,u,i)]);s.push(...d)}return s}async getAssignPoolList(e){if(e.length===0)return[];let t=[];try{let r=await this._sdk.FullClient.batchGetObjects(e,{showContent:!0,showType:!0});for(let i of r){let s=Pe(i),u=`${s.id}_getDlmmPool`;this._sdk.updateCache(u,s),t.push(s)}}catch(r){return K("FetchError",r,{[X.DETAILS_KEYS.METHOD_NAME]:"getAssignPoolList"})}return t}async getPool(e,t=!0){try{let r=`${e}_getDlmmPool`,i=this._sdk.getCache(r,t);if(i!==void 0)return i;let s=await this._sdk.FullClient.getObject({id:e,options:{showType:!0,showContent:!0}}),u=Pe(s);return this._sdk.updateCache(r,u),u}catch(r){return K("FetchError",r,{[X.DETAILS_KEYS.METHOD_NAME]:"getPool",[X.DETAILS_KEYS.REQUEST_PARAMS]:e})}}async createPoolAndAddWithPricePayload(e){let{bin_step:t,url:r,coin_type_a:i,coin_type_b:s,bin_infos:u,price_base_coin:d,price:f,lower_price:h,upper_price:p,decimals_a:w,decimals_b:y,strategy_type:A,use_bin_infos:B,base_factor:S}=e,T,x,k,I=u;if(d==="coin_a")T=D.getBinIdFromPrice(h,t,!1,w,y),x=D.getBinIdFromPrice(p,t,!0,w,y),k=D.getBinIdFromPrice(f,t,!0,w,y);else{T=D.getBinIdFromPrice((0,X.d)(1).div(p).toString(),t,!1,w,y),x=D.getBinIdFromPrice((0,X.d)(1).div(h).toString(),t,!0,w,y),k=D.getBinIdFromPrice((0,X.d)(1).div(f).toString(),t,!1,w,y);let Q={amount_a:u.amount_b,amount_b:u.amount_a,active_id:k,bin_step:t,lower_bin_id:T,upper_bin_id:x,amount_a_in_active_bin:"0",amount_b_in_active_bin:"0",strategy_type:e.strategy_type};I=this.sdk.Position.calculateAddLiquidityInfo(Q)}let z={bin_step:t,url:r,coin_type_a:i,coin_type_b:s,bin_infos:I,lower_bin_id:T,upper_bin_id:x,active_id:k,strategy_type:A,use_bin_infos:B,base_factor:S};return this.createPoolAndAddLiquidityPayload(z)}async createPoolPayload(e,t){let{dlmm_pool:r}=this._sdk.sdkOptions,{bin_step:i,base_factor:s,url:u,coin_type_a:d,coin_type_b:f,active_id:h}=e;t=t||new Ae.Transaction;let{registry_id:p,global_config_id:w,versioned_id:y}=(0,X.getPackagerConfigs)(r),A=await this._sdk.FullClient.fetchCoinMetadata(d);A?.id||K("FetchError",new Error(`coin_a_metadata not found: ${d}`),{[X.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityPayload",[X.DETAILS_KEYS.REQUEST_PARAMS]:e});let B=await this._sdk.FullClient.fetchCoinMetadata(f);B?.id||K("FetchError",new Error(`coin_b_metadata not found: ${f}`),{[X.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityPayload",[X.DETAILS_KEYS.REQUEST_PARAMS]:e});let[S,T]=t.moveCall({target:`${r.published_at}::registry::create_pool`,arguments:[t.object(p),t.object(A.id),t.object(B.id),t.pure.u16(i),t.pure.u16(s),t.pure.u32(Number((0,X.asUintN)(BigInt(h)))),t.pure.string(u||""),t.object(w),t.object(y),t.object(X.CLOCK_ADDRESS)],typeArguments:[d,f]});return t.moveCall({target:`${r.published_at}::registry::destroy_receipt`,arguments:[t.object(S),T,t.object(y)],typeArguments:[d,f]}),T}async createPoolAndAddLiquidityPayload(e){let{dlmm_pool:t}=this._sdk.sdkOptions,{bin_step:r,base_factor:i,url:s,active_id:u,coin_type_a:d,coin_type_b:f,bin_infos:h,lower_bin_id:p,upper_bin_id:w,strategy_type:y,use_bin_infos:A}=e,{registry_id:B,global_config_id:S,versioned_id:T}=(0,X.getPackagerConfigs)(t),x=new Ae.Transaction;(0,X.isSortedSymbols)((0,X.fixCoinType)(d,!1),(0,X.fixCoinType)(f,!1))&&K("InvalidCoinTypeSequence",new Error("invalid coin type sequence"),{[X.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityPayload",[X.DETAILS_KEYS.REQUEST_PARAMS]:e});let k=w-p+1;k>1e3&&K("InvalidBinWidth",new Error("Width is too large"),{[X.DETAILS_KEYS.METHOD_NAME]:"openPosition",[X.DETAILS_KEYS.REQUEST_PARAMS]:e}),(await this._sdk.FullClient.fetchCoinMetadata(d))?.id||K("FetchError",new Error(`coin_a_metadata not found: ${d}`),{[X.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityPayload",[X.DETAILS_KEYS.REQUEST_PARAMS]:e}),(await this._sdk.FullClient.fetchCoinMetadata(f))?.id||K("FetchError",new Error(`coin_b_metadata not found: ${f}`),{[X.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityPayload",[X.DETAILS_KEYS.REQUEST_PARAMS]:e}),console.log("\u{1F680} ~ createPoolAndAddLiquidityPayload ~ option:",{...e,width:k});let Q={pool_id:await this.createPoolPayload({active_id:u,bin_step:r,base_factor:i,coin_type_a:d,coin_type_b:f},x),bin_infos:h,coin_type_a:d,coin_type_b:f,lower_bin_id:p,upper_bin_id:w,active_id:u,strategy_type:y,use_bin_infos:A,max_price_slippage:0,bin_step:r};return this.sdk.Position.addLiquidityPayload(Q,x),x}};var Sr=require("@cetusprotocol/common-sdk"),Ni={env:"testnet",full_rpc_url:Sr.FullRpcUrlTestnet,dlmm_pool:{package_id:"0x17a1f5a8779461ff44e942adf33325cce112c693d6a177ed77f035ca86d1fdb6",published_at:"0x17a1f5a8779461ff44e942adf33325cce112c693d6a177ed77f035ca86d1fdb6",version:1,config:{registry_id:"0x319070e26a6809f439d3c4a45e63bf74939c5fe3165de7b65968ee8547f71bd0",pools_id:"0x505fcde74ab557d553832a87f169a0408ad3507ca4e84b25f7d32c2c1535765c",global_config_id:"0x88bb33e9eff2fccab980a0e4b43fc4572abd08f08304d47a20d3e4e99d94d159",versioned_id:"0xa710caae87b2129acc97fbb98ea7011e3137c3291b02c0fcce866d67d5d9e8d0",admin_cap_id:"0x6fc908894ad7c2ff16cca07a05af6760831a8b5e5dc34e40470dce6ee1760155",partners_id:"0xc5c31fe1550e39c9890e0fe3d2608dd9b408a10d74020e5ff72ccfffe4c9c879"}},dlmm_router:{package_id:"0x70777a78c17b550170924b4bf598fa6d883106521cc02eda798401a315b6751b",published_at:"0x70777a78c17b550170924b4bf598fa6d883106521cc02eda798401a315b6751b",version:1},faucet:{package_id:"0x14a71d857b34677a7d57e0feb303df1adb515a37780645ab763d42ce8d1a5e48",published_at:"0x14a71d857b34677a7d57e0feb303df1adb515a37780645ab763d42ce8d1a5e48",version:1}};var O=require("@cetusprotocol/common-sdk"),he=require("@mysten/sui/transactions"),Br=require("@mysten/sui/utils");var $e=class{constructor(e){this._sdk=e}get sdk(){return this._sdk}buildPositionType(){return`${this._sdk.sdkOptions.dlmm_pool.package_id}::position::Position`}async getOwnerPositionList(e){let t=[];try{(await this._sdk.FullClient.getOwnedObjectsByPage(e,{options:{showType:!0,showContent:!0,showOwner:!0},filter:{StructType:this.buildPositionType()}})).data.forEach(i=>{t.push(Ke(i))})}catch(r){console.log("\u{1F680} ~ PositionModule ~ getOwnerPositionList ~ error:",r),K("GetObjectError",r,{[O.DETAILS_KEYS.METHOD_NAME]:"getOwnerPositionList",[O.DETAILS_KEYS.REQUEST_PARAMS]:e})}return t}async getPosition(e){try{let t=await this._sdk.FullClient.getObject({id:e,options:{showType:!0,showContent:!0,showOwner:!0}});return Ke(t)}catch(t){return console.log("\u{1F680} ~ PositionModule ~ getPosition ~ error:",t),K("GetObjectError",t,{[O.DETAILS_KEYS.METHOD_NAME]:"getPosition",[O.DETAILS_KEYS.REQUEST_PARAMS]:e})}}collectFeePayload(e,t){let{pool_id:r,position_id:i,coin_type_a:s,coin_type_b:u}=e,{dlmm_pool:d}=this.sdk.sdkOptions,{versioned_id:f,global_config_id:h}=(0,O.getPackagerConfigs)(d);t=t||new he.Transaction;let[p,w]=t.moveCall({target:`${d.published_at}::pool::collect_position_fee`,arguments:[t.object(r),t.object(i),t.object(h),t.object(f)],typeArguments:[s,u]}),y=O.CoinAssist.fromBalance(p,s,t),A=O.CoinAssist.fromBalance(w,u,t);return t.transferObjects([y,A],this.sdk.getSenderAddress()),t}updatePositionFeeAndRewards(e,t){let{dlmm_pool:r}=this.sdk.sdkOptions,{versioned_id:i}=(0,O.getPackagerConfigs)(r),{pool_id:s,position_id:u,coin_type_a:d,coin_type_b:f}=e;return t.moveCall({target:`${r.published_at}::pool::update_position_fee_and_rewards`,arguments:[t.object(s),t.pure.id(u),t.object(i),t.object(O.CLOCK_ADDRESS)],typeArguments:[d,f]}),t}collectRewardPayload(e,t){let{dlmm_pool:r}=this.sdk.sdkOptions,{versioned_id:i,global_config_id:s}=(0,O.getPackagerConfigs)(r);return t=t||new he.Transaction,e.forEach(u=>{let{pool_id:d,position_id:f,reward_coins:h,coin_type_a:p,coin_type_b:w}=u;h.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(i)],typeArguments:[p,w,y]}),B=O.CoinAssist.fromBalance(A,y,t);t.transferObjects([B],this.sdk.getSenderAddress())})}),t}collectRewardAndFeePayload(e,t){return t=t||new he.Transaction,e.forEach(r=>{let{pool_id:i,position_id:s,reward_coins:u,coin_type_a:d,coin_type_b:f}=r;this.updatePositionFeeAndRewards({pool_id:i,position_id:s,coin_type_a:d,coin_type_b:f},t),this.collectFeePayload({pool_id:i,position_id:s,coin_type_a:d,coin_type_b:f},t),this.collectRewardPayload([{pool_id:i,position_id:s,reward_coins:u,coin_type_a:d,coin_type_b:f}],t)}),t}validateActiveIdSlippage(e,t){let{pool_id:r,active_id:i,max_price_slippage:s,bin_step:u,coin_type_a:d,coin_type_b:f}=e,{dlmm_router:h}=this.sdk.sdkOptions,p=D.getBinShift(i,u,s),w=Number((0,O.asUintN)(BigInt(i)));return t.moveCall({target:`${h.published_at}::utils::validate_active_id_slippage`,arguments:[typeof r=="string"?t.object(r):r,t.pure.u32(Number(w)),t.pure.u32(Number(p))],typeArguments:[d,f]}),t}closePositionPayload(e,t){let{pool_id:r,position_id:i,reward_coins:s,coin_type_a:u,coin_type_b:d}=e,{dlmm_pool:f}=this.sdk.sdkOptions,{versioned_id:h,global_config_id:p}=(0,O.getPackagerConfigs)(f);t=t||new he.Transaction,this.updatePositionFeeAndRewards({pool_id:r,position_id:i,coin_type_a:u,coin_type_b:d},t),this.collectRewardPayload([{pool_id:r,position_id:i,reward_coins:s,coin_type_a:u,coin_type_b:d}],t);let[w,y,A]=t.moveCall({target:`${f.published_at}::pool::close_position`,arguments:[t.object(r),t.object(i),t.object(p),t.object(h),t.object(O.CLOCK_ADDRESS)],typeArguments:[u,d]}),B=O.CoinAssist.fromBalance(y,u,t),S=O.CoinAssist.fromBalance(A,d,t);return t.moveCall({target:`${f.published_at}::pool::destroy_close_position_cert`,arguments:[w,t.object(h)],typeArguments:[]}),t.transferObjects([B,S],this.sdk.getSenderAddress()),t}async getActiveBinIfInRange(e,t,r,i,s,u=!1){if(i<=r&&i>=t)return await this._sdk.Pool.getBinInfo(e,i,s,u)}calculateRemoveLiquidityInfo(e){let{bins:t,active_id:r,coin_amount:i}=e,s="fix_amount_a"in e,u=t.filter(y=>y.bin_id<r),d=t.filter(y=>y.bin_id>r),f=(0,O.d)(0),h=(0,O.d)(0),p=[];if(s){p=[...t];let{fix_amount_a:y}=e,A=t.find(T=>T.bin_id===r),B=d.reduce((T,x)=>(0,O.d)(T).plus(x.amount_a),(0,O.d)(0)).add(A?.amount_a||"0"),S=u.reduce((T,x)=>(0,O.d)(T).plus(x.amount_b),(0,O.d)(0)).add(A?.amount_b||"0");f=y?B:S,h=(0,O.d)(i).gte(f)?(0,O.d)(1):(0,O.d)(i).div(f)}else{let{is_only_a:y}=e;p=y?d:u,f=p.reduce((A,B)=>(0,O.d)(A).plus(y?B.amount_a:B.amount_b),(0,O.d)(0)),h=(0,O.d)(i).gte(f)?(0,O.d)(1):(0,O.d)(i).div(f)}if((0,O.d)(f).isZero())return K("InsufficientLiquidity",new Error("Insufficient liquidity"),{[O.DETAILS_KEYS.METHOD_NAME]:"calculateRemoveLiquidityResult",[O.DETAILS_KEYS.REQUEST_PARAMS]:e});let w=D.processBinsByRate([...p],h.toFixed());if(w.has_invalid_amount){let y=(0,O.d)(i),A=[],B=s?e.fix_amount_a:e.is_only_a;for(let S of p){if(y.lte(0))break;let T=B?S.amount_a:S.amount_b,x=B?S.amount_b:S.amount_a,k=(0,O.d)((0,O.d)(y).div(T).toFixed(9,F.ROUND_UP));k=k.gt(1)?(0,O.d)(1):k;let I=(0,O.d)(T).mul(k);y=y.minus(I);let C=(0,O.d)(x).mul(k),z=(0,O.d)(S.liquidity).mul(k);A.push({...S,amount_a:B?I.toFixed(0):C.toFixed(0),amount_b:B?C.toFixed(0):I.toFixed(0),liquidity:z.toFixed(0)})}return{bins:A,amount_a:A.reduce((S,T)=>(0,O.d)(S).plus(T.amount_a),(0,O.d)(0)).toFixed(0),amount_b:A.reduce((S,T)=>(0,O.d)(S).plus(T.amount_b),(0,O.d)(0)).toFixed(0)}}return w.bins}calculateAddLiquidityInfo(e){let t="fix_amount_a"in e,{active_id:r,bin_step:i,lower_bin_id:s,upper_bin_id:u,amount_a_in_active_bin:d,amount_b_in_active_bin:f,strategy_type:h}=e;if(t){let{coin_amount:p,fix_amount_a:w}=e;return ve.autoFillCoinByStrategy(r,i,p,w,d,f,s,u,h)}else return ve.toAmountsBothSideByStrategy(r,i,s,u,e.amount_a,e.amount_b,d,f,h)}removeLiquidityPayload(e){let{pool_id:t,position_id:r,bin_infos:i,reward_coins:s,slippage:u,coin_type_a:d,coin_type_b:f,active_id:h,collect_fee:p,bin_step:w,remove_percent:y}=e,{dlmm_pool:A}=this.sdk.sdkOptions,{bins:B}=i,S=new he.Transaction;(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:x}=(0,O.getPackagerConfigs)(A);if(y){let k=(0,O.asUintN)(BigInt(B[0].bin_id)),I=(0,O.asUintN)(BigInt(B[B.length-1].bin_id)),C=Number((0,O.d)(y).mul(1e4).toFixed(0)),[z,Q]=S.moveCall({target:`${A.published_at}::pool::remove_liquidity_by_percent`,arguments:[S.object(t),S.object(r),S.pure.u32(Number(k)),S.pure.u32(Number(I)),S.pure.u16(C),S.object(x),S.object(T),S.object(O.CLOCK_ADDRESS)],typeArguments:[d,f]}),it=O.CoinAssist.fromBalance(z,d,S),at=O.CoinAssist.fromBalance(Q,f,S);S.transferObjects([it,at],this.sdk.getSenderAddress())}else{let k=S.pure.vector("u32",B.map(at=>Number((0,O.asUintN)(BigInt(at.bin_id))))),I=S.pure.vector("u128",B.map(at=>at.liquidity)),[C,z]=S.moveCall({target:`${A.published_at}::pool::remove_liquidity`,arguments:[S.object(t),S.object(r),k,I,S.object(x),S.object(T),S.object(O.CLOCK_ADDRESS)],typeArguments:[d,f]}),Q=O.CoinAssist.fromBalance(C,d,S),it=O.CoinAssist.fromBalance(z,f,S);S.transferObjects([Q,it],this.sdk.getSenderAddress())}return this.validateActiveIdSlippage({pool_id:t,active_id:h,max_price_slippage:u,bin_step:w,coin_type_a:d,coin_type_b:f},S),S}addLiquidityWithPricePayload(e){let{pool_id:t,bin_infos:r,coin_type_a:i,coin_type_b:s,price_base_coin:u,price:d,lower_price:f,upper_price:h,bin_step:p,strategy_type:w,amount_a_in_active_bin:y,amount_b_in_active_bin:A,decimals_a:B,decimals_b:S,use_bin_infos:T,max_price_slippage:x}=e,k,I,C,z=r;if(u==="coin_a")k=D.getBinIdFromPrice(f,p,!1,B,S),I=D.getBinIdFromPrice(h,p,!0,B,S),C=D.getBinIdFromPrice(d,p,!0,B,S);else{k=D.getBinIdFromPrice((0,O.d)(1).div(h).toString(),p,!1,B,S),I=D.getBinIdFromPrice((0,O.d)(1).div(f).toString(),p,!0,B,S),C=D.getBinIdFromPrice((0,O.d)(1).div(d).toString(),p,!1,B,S);let at={amount_a:r.amount_b,amount_b:r.amount_a,active_id:C,bin_step:p,lower_bin_id:k,upper_bin_id:I,amount_a_in_active_bin:y,amount_b_in_active_bin:A,strategy_type:w};z=this.sdk.Position.calculateAddLiquidityInfo(at)}let it={pool_id:t,active_id:C,bin_infos:z,coin_type_a:i,coin_type_b:s,lower_bin_id:k,upper_bin_id:I,strategy_type:w,use_bin_infos:T,max_price_slippage:x,bin_step:p};return this.addLiquidityPayload(it)}addLiquidityPayload(e,t){let{pool_id:r,bin_infos:i,coin_type_a:s,coin_type_b:u,active_id:d,strategy_type:f,max_price_slippage:h,bin_step:p,use_bin_infos:w=!1}=e;t=t||new he.Transaction;let y="lower_bin_id"in e,A=[];if(y){let B=D.splitBinLiquidityInfo(i,e.lower_bin_id,e.upper_bin_id);A.push(...B)}else{let B=e.position_id;A.push(i),(e.collect_fee||e.reward_coins.length>0)&&this.updatePositionFeeAndRewards({pool_id:r,position_id:B,coin_type_a:s,coin_type_b:u},t),e.collect_fee&&this.collectFeePayload({pool_id:r,position_id:B,coin_type_a:s,coin_type_b:u},t),e.reward_coins.length>0&&this.collectRewardPayload([{pool_id:r,position_id:B,reward_coins:e.reward_coins,coin_type_a:s,coin_type_b:u}],t)}return A.forEach((B,S)=>{console.log("\u{1F680} ~ PositionModule ~ addLiquidityPayload ~ liquidity_bin:",S,B);let{amount_a:T,amount_b:x,bins:k}=B,I=O.CoinAssist.buildCoinWithBalance(BigInt(T),s,t),C=O.CoinAssist.buildCoinWithBalance(BigInt(x),u,t);w?this.addLiquidityInternal({pool_id:r,coin_type_a:s,coin_type_b:u,active_id:d,liquidity_bin:B,tx:t,coin_a_obj_id:I,coin_b_obj_id:C,position_id:y?void 0:e.position_id,max_price_slippage:h,bin_step:p}):this.addLiquidityStrategyInternal({pool_id:r,coin_type_a:s,coin_type_b:u,active_id:d,liquidity_bin:B,tx:t,max_price_slippage:h,bin_step:p,coin_a_obj_id:I,coin_b_obj_id:C,strategy_type:f,position_id:y?void 0:e.position_id})}),t}addLiquidityStrategyInternal(e){let{max_price_slippage:t,bin_step:r,position_id:i,pool_id:s,coin_type_a:u,coin_type_b:d,active_id:f,liquidity_bin:h,tx:p,coin_a_obj_id:w,coin_b_obj_id:y,strategy_type:A}=e,{dlmm_pool:B,dlmm_router:S}=this.sdk.sdkOptions,{versioned_id:T,global_config_id:x}=(0,O.getPackagerConfigs)(B),{bins:k,amount_a:I,amount_b:C}=h,z=i,Q=k[0].bin_id,it=k[k.length-1].bin_id,at=(0,O.asUintN)(BigInt(Q)),Kt=Number((0,O.asUintN)(BigInt(f))),$t=D.getBinShift(f,r,t),H=ki(A);if(i===void 0){let rt=it-Q+1;rt>1e3&&K("InvalidBinWidth",new Error("Width is too large"),{[O.DETAILS_KEYS.METHOD_NAME]:"openPosition"}),z=p.moveCall({target:`${S.published_at}::${H}::open_position`,arguments:[typeof s=="string"?p.object(s):s,w,y,p.pure.u64(I),p.pure.u64(C),p.pure.u32(Number(at)),p.pure.u16(Number(rt)),p.pure.u32(Number(Kt)),p.pure.u32(Number($t)),p.object(x),p.object(T),p.object(O.CLOCK_ADDRESS)],typeArguments:[u,d]})}else{let rt=k.filter(l=>l.amount_a!=="0"||l.amount_b!=="0");if(rt.length===0)return K("InvalidParams",new Error("No bins to add liquidity"),{[O.DETAILS_KEYS.METHOD_NAME]:"addLiquidityStrategyInternal",[O.DETAILS_KEYS.REQUEST_PARAMS]:e});let v=(0,O.asUintN)(BigInt(rt[0].bin_id)),o=(0,O.asUintN)(BigInt(rt[rt.length-1].bin_id));p.moveCall({target:`${S.published_at}::${H}::add_liquidity`,arguments:[typeof s=="string"?p.object(s):s,p.object(i),w,y,p.pure.u64(I),p.pure.u64(C),p.pure.u32(Number(v)),p.pure.u32(Number(o)),p.pure.u32(Number(Kt)),p.pure.u32(Number($t)),p.object(x),p.object(T),p.object(O.CLOCK_ADDRESS)],typeArguments:[u,d]})}return z?p.transferObjects([z,w,y],this.sdk.getSenderAddress()):p.transferObjects([w,y],this.sdk.getSenderAddress()),p}addLiquidityInternal(e){let{position_id:t,pool_id:r,coin_type_a:i,coin_type_b:s,active_id:u,liquidity_bin:d,tx:f,coin_a_obj_id:h,coin_b_obj_id:p,max_price_slippage:w,bin_step:y}=e,{bins:A}=d,{dlmm_pool:B,dlmm_router:S}=this.sdk.sdkOptions,{versioned_id:T,global_config_id:x}=(0,O.getPackagerConfigs)(B),k=f.pure.vector("u64",A.map(it=>it.amount_a)),I=f.pure.vector("u64",A.map(it=>it.amount_b)),C=f.makeMoveVec({elements:A.map(it=>f.pure.u32(Number((0,O.asUintN)(BigInt(it.bin_id))))),type:"u32"}),z=d.bins[0].bin_id,Q=d.bins[d.bins.length-1].bin_id;if(t===void 0){Q-z+1>1e3&&K("InvalidBinWidth",new Error("Width is too large"),{[O.DETAILS_KEYS.METHOD_NAME]:"openPosition"});let at=f.moveCall({target:`${S.published_at}::add_liquidity::open_position`,arguments:[typeof r=="string"?f.object(r):r,h,p,C,k,I,f.object(x),f.object(T),f.object(O.CLOCK_ADDRESS)],typeArguments:[i,s]});u>=z&&u<=Q&&this.validateActiveIdSlippage({pool_id:r,active_id:u,max_price_slippage:w,bin_step:y,coin_type_a:i,coin_type_b:s},f),f.transferObjects([h,p,at],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),h,p,C,k,I,f.object(x),f.object(T),f.object(O.CLOCK_ADDRESS)],typeArguments:[i,s]}),u>=z&&u<=Q&&this.validateActiveIdSlippage({pool_id:r,active_id:u,max_price_slippage:w,bin_step:y,coin_type_a:i,coin_type_b:s},f),f.transferObjects([h,p],this.sdk.getSenderAddress());return f}async fetchPositionFeeAndReward(e){let t=new he.Transaction;this.collectRewardAndFeePayload(e,t);let r=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:t,sender:(0,Br.normalizeSuiAddress)("0x0")});if(r.error!=null)return K("FetchError",new Error(r.error),{[O.DETAILS_KEYS.METHOD_NAME]:"fetchPositionFeeAndReward",[O.DETAILS_KEYS.REQUEST_PARAMS]:{options:e,totalOptions:e.length}});let i=Oi(r),s=Ci(r);return{feeData:i,rewardData:s}}};var qi=require("@mysten/sui/transactions"),Gt=require("@cetusprotocol/common-sdk");var Er=require("@mysten/sui/utils");var ze=class{constructor(e){this._sdk=e}get sdk(){return this._sdk}async preSwapQuote(e){let{dlmm_pool:t}=this._sdk.sdkOptions,{pool_id:r,coin_type_a:i,coin_type_b:s,a2b:u,by_amount_in:d,in_amount:f}=e,{versioned_id:h,global_config_id:p}=(0,Gt.getPackagerConfigs)(t),w=new qi.Transaction;w.moveCall({target:`${t.published_at}::pool::flash_swap`,arguments:[w.object(r),w.pure.bool(u),w.pure.bool(d),w.pure.u64(f),w.object(p),w.object(h),w.object(Gt.CLOCK_ADDRESS)],typeArguments:[i,s]});let y=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:w,sender:(0,Er.normalizeSuiAddress)("0x0")});if(y.error!=null)return K("FetchError",new Error(y.error),{[Gt.DETAILS_KEYS.METHOD_NAME]:"fetchSwapQuote",[Gt.DETAILS_KEYS.REQUEST_PARAMS]:e});let A=Ti(y,u);return A==null?K("FetchError",new Error("No quote info"),{[Gt.DETAILS_KEYS.METHOD_NAME]:"preSwapQuote",[Gt.DETAILS_KEYS.REQUEST_PARAMS]:e}):(A.a2b=u,A)}swapPayload(e){let{dlmm_pool:t,dlmm_router:r}=this._sdk.sdkOptions,{quote_obj:i,coin_type_a:s,coin_type_b:u,by_amount_in:d,slippage:f,partner:h}=e,{pool_id:p,in_amount:w,out_amount:y,a2b:A}=i,B=new qi.Transaction,S=d?w:(0,Gt.d)(w).mul(1+f).toFixed(0),T=d?(0,Gt.d)(y).mul(1-f).toFixed(0):y,x=Gt.CoinAssist.buildCoinWithBalance(BigInt(S),A?s:u,B),{versioned_id:k,global_config_id:I}=(0,Gt.getPackagerConfigs)(t);return console.log("\u{1F680} ~ SwapModule ~ option:",{...e,in_amount_limit:S,out_amount_limit:T}),h?B.moveCall({target:`${r.published_at}::swap::${A?"swap_a2b_with_partner":"swap_b2a_with_partner"}`,arguments:[B.object(p),B.object(h),x,B.pure.bool(d),B.pure.u64(BigInt(d?w:y)),B.pure.u64(BigInt(d?T:S)),B.object(I),B.object(k),B.object(Gt.CLOCK_ADDRESS)],typeArguments:[s,u]}):B.moveCall({target:`${r.published_at}::swap::${A?"swap_a2b":"swap_b2a"}`,arguments:[B.object(p),x,B.pure.bool(d),B.pure.u64(BigInt(d?w:y)),B.pure.u64(BigInt(d?T:S)),B.object(I),B.object(k),B.object(Gt.CLOCK_ADDRESS)],typeArguments:[s,u]}),B.transferObjects([x],this.sdk.getSenderAddress()),B}};var Ee=require("@mysten/sui/transactions"),J=require("@cetusprotocol/common-sdk");var Ge=class{constructor(e){this._sdk=e}get sdk(){return this._sdk}async getPartnerList(){let e=[],{dlmm_pool:t}=this._sdk.sdkOptions,{partners_id:r}=(0,J.getPackagerConfigs)(t);try{let i=await this._sdk.FullClient.getObject({id:r,options:{showContent:!0}}),u=(0,J.getObjectFields)(i).partners.fields.contents.map(d=>d.fields.value);u.length>0&&(await this._sdk.FullClient.batchGetObjects(u,{showContent:!0,showType:!0})).forEach(f=>{let h=Qe(f);e.push(h)})}catch(i){return K("FetchError",i,{[J.DETAILS_KEYS.METHOD_NAME]:"getPartnerList",[J.DETAILS_KEYS.REQUEST_PARAMS]:r})}return e}async getPartnerCapId(e,t){let{dlmm_pool:r}=this._sdk.sdkOptions;try{let i=`partner_cap_id_${e}_${t}`,s=this._sdk.getCache(i);if(s)return s;let u=await this._sdk.FullClient.getOwnedObjects({owner:e,options:{showContent:!0,showType:!0},filter:{StructType:`${r.package_id}::partner::PartnerCap`}}),d;return u.data.forEach(f=>{let h=(0,J.getObjectFields)(f);h.partner_id===t&&(d=h.id.id,this._sdk.updateCache(i,d))}),d||K("NotFound",new Error("Partner cap not found"),{[J.DETAILS_KEYS.METHOD_NAME]:"getPartnerCapId",[J.DETAILS_KEYS.REQUEST_PARAMS]:{owner:e,partner_id:t}})}catch(i){return K("FetchError",i,{[J.DETAILS_KEYS.METHOD_NAME]:"getPartnerCapId",[J.DETAILS_KEYS.REQUEST_PARAMS]:{owner:e,partner_id:t}})}}async getPartnerBalance(e){try{let t=await this._sdk.FullClient.getDynamicFieldsByPage(e),r=[],i=t.data.map(s=>s.objectId);return i.length>0&&(await this._sdk.FullClient.batchGetObjects(i,{showContent:!0,showType:!0})).forEach(u=>{let d=(0,J.getObjectFields)(u);console.log(d),r.push({coin_type:(0,J.fixCoinType)(d.name,!1),balance:d.value})}),r}catch(t){return K("FetchError",t,{[J.DETAILS_KEYS.METHOD_NAME]:"getPartnerBalance",[J.DETAILS_KEYS.REQUEST_PARAMS]:e})}}async getPartner(e){try{let t=await this._sdk.FullClient.getObject({id:e,options:{showContent:!0}});return Qe(t)}catch(t){return K("FetchError",t,{[J.DETAILS_KEYS.METHOD_NAME]:"getPartner",[J.DETAILS_KEYS.REQUEST_PARAMS]:e})}}updateRefFeeRatePayload(e,t){let{dlmm_pool:r}=this._sdk.sdkOptions,{partner_id:i,ref_fee_rate:s}=e,{global_config_id:u,versioned_id:d}=(0,J.getPackagerConfigs)(r);t=t||new Ee.Transaction;let f=(0,J.d)(s).mul(1e4);return f.gt(1e4)?K("InvalidParams",new Error("ref_fee_rate is cannot be greater than 1"),{[J.DETAILS_KEYS.METHOD_NAME]:"updateRefFeeRatePayload",[J.DETAILS_KEYS.REQUEST_PARAMS]:e}):(t.moveCall({target:`${r.published_at}::partner::update_ref_fee_rate`,arguments:[t.object(i),t.pure.u64(f.toNumber()),t.object(u),t.object(d)],typeArguments:[]}),t)}async claimRefFeePayload(e){let{partner_id:t,partner_cap_id:r,fee_coin_types:i}=e,{dlmm_pool:s}=this._sdk.sdkOptions,{versioned_id:u}=(0,J.getPackagerConfigs)(s),d=new Ee.Transaction,f=r;return f||(f=await this.getPartnerCapId(this._sdk.getSenderAddress(),t)),i.forEach(h=>{d.moveCall({target:`${s.published_at}::partner::claim_ref_fee`,arguments:[d.object(t),d.object(f),d.object(u)],typeArguments:[h]})}),d}updateTimeRangePayload(e,t){let{dlmm_pool:r}=this._sdk.sdkOptions,{partner_id:i,start_time:s,end_time:u}=e,{global_config_id:d,versioned_id:f}=(0,J.getPackagerConfigs)(r);t=t||new Ee.Transaction;let h=s>1e12?Math.floor(s/1e3):s,p=u>1e12?Math.floor(u/1e3):u;return p<=h?K("InvalidParams",new Error("end_time must be greater than start_time"),{[J.DETAILS_KEYS.METHOD_NAME]:"createPartnerPayload",[J.DETAILS_KEYS.REQUEST_PARAMS]:e}):(t.moveCall({target:`${r.published_at}::partner::update_time_range`,arguments:[t.object(i),t.pure.u64(h),t.pure.u64(p),t.object(d),t.object(f),t.object(J.CLOCK_ADDRESS)],typeArguments:[]}),t)}createPartnerPayload(e){let{dlmm_pool:t}=this._sdk.sdkOptions,{name:r,ref_fee_rate:i,start_time:s,end_time:u,recipient:d}=e,{partners_id:f,global_config_id:h,versioned_id:p}=(0,J.getPackagerConfigs)(t),w=new Ee.Transaction,y=(0,J.d)(i).mul(1e4);if(y.gt(1e4))return K("InvalidParams",new Error("ref_fee_rate is cannot be greater than 1"),{[J.DETAILS_KEYS.METHOD_NAME]:"createPartnerPayload",[J.DETAILS_KEYS.REQUEST_PARAMS]:e});let A=s>1e12?Math.floor(s/1e3):s,B=u>1e12?Math.floor(u/1e3):u;return B<=A?K("InvalidParams",new Error("end_time must be greater than start_time"),{[J.DETAILS_KEYS.METHOD_NAME]:"createPartnerPayload",[J.DETAILS_KEYS.REQUEST_PARAMS]:e}):(w.moveCall({target:`${t.published_at}::partner::create_partner`,arguments:[w.object(f),w.pure.string(r),w.pure.u64(y.toNumber()),w.pure.u64(A),w.pure.u64(B),w.pure.address(d),w.object(h),w.object(p)],typeArguments:[]}),w)}};var Ve=require("@mysten/sui/transactions"),ut=require("@cetusprotocol/common-sdk"),Li=bi(Ce()),Xe=class{constructor(e){this._sdk=e}get sdk(){return this._sdk}async getRewardPeriodEmission(e,t,r){let i=await this._sdk.FullClient.getDynamicFieldsByPage(e),s=[],u=i.data.map(p=>p.objectId);u.length>0&&(await this._sdk.FullClient.batchGetObjects(u,{showContent:!0})).forEach(w=>{let y=(0,ut.getObjectFields)(w),A=ut.MathUtil.u128ToI128(new Li.default(y.value.fields.value.fields.bits)).toString(),B=y.name,S=new Date(Number(B)*1e3).toLocaleString(),x={emissions_per_second:"0",emissions_per_day:"0",emissions_per:ut.MathUtil.fromX64(new Li.default(A)).toString(),time:B,visualized_time:S};s.push(x)});let d=s.sort((p,w)=>Number(p.time)-Number(w.time)),f=[];f.push({emissions_per_second:t,emissions_per_day:(0,ut.d)(t).mul(3600*24).toString(),emissions_per:"0",time:r.toString(),visualized_time:new Date(r*1e3).toLocaleString()});let h=t;for(let p=0;p<d.length;p++){let w=d[p];if((0,ut.d)(w.time).lte(r))continue;h=(0,ut.d)(h).add((0,ut.d)(w.emissions_per)).toString();let y=(0,ut.d)(h).mul(3600*24).toString();(0,ut.d)(h).lt(0)?(w.emissions_per_second="0",w.emissions_per_day="0"):(w.emissions_per_second=h,w.emissions_per_day=y),f.push(w)}return f}addRewardPayload(e,t){t=t||new Ve.Transaction;let{dlmm_pool:r}=this._sdk.sdkOptions,{global_config_id:i,versioned_id:s}=(0,ut.getPackagerConfigs)(r),{pool_id:u,reward_coin_type:d,reward_amount:f,start_time_seconds:h,end_time_seconds:p,coin_type_a:w,coin_type_b:y}=e,A=ut.CoinAssist.buildCoinWithBalance(BigInt(f),d,t);return t.pure.option("u64",h),t.moveCall({target:`${r.published_at}::pool::add_reward`,arguments:[t.object(u),A,t.pure.option("u64",h),t.pure.u64(p),t.object(i),t.object(s),t.object(ut.CLOCK_ADDRESS)],typeArguments:[w,y,d]}),t}initRewardPayload(e,t){t=t||new Ve.Transaction;let{dlmm_pool:r}=this._sdk.sdkOptions,{global_config_id:i,versioned_id:s}=(0,ut.getPackagerConfigs)(r),{pool_id:u,reward_coin_types:d,coin_type_a:f,coin_type_b:h}=e;return d.forEach(p=>{t.moveCall({target:`${r.published_at}::pool::initialize_reward`,arguments:[t.object(u),t.object(i),t.object(s),t.object(ut.CLOCK_ADDRESS)],typeArguments:[f,h,p]})}),t}buildRewardAccessPayload(e,t){t=t||new Ve.Transaction;let{dlmm_pool:r}=this._sdk.sdkOptions,{global_config_id:i,versioned_id:s}=(0,ut.getPackagerConfigs)(r),{pool_id:u,type:d,coin_type_a:f,coin_type_b:h}=e;return t.moveCall({target:`${r.published_at}::pool::${d==="to_public"?"make_reward_public":"make_reward_private"}`,arguments:[t.object(u),t.object(i),t.object(s)],typeArguments:[f,h]}),t}};var Ir=require("@mysten/sui/transactions"),ee=require("@cetusprotocol/common-sdk");var Je=class{constructor(e){this._sdk=e}get sdk(){return this._sdk}buildRewardWhiteListPayload(e,t){t=t||new Ir.Transaction;let{dlmm_pool:r}=this._sdk.sdkOptions,{global_config_id:i,versioned_id:s}=(0,ee.getPackagerConfigs)(r),{reward_coin_types:u,type:d}=e;return u.forEach(f=>{t.moveCall({target:`${r.published_at}::config::${d==="add"?"add_reward_whitelist":"remove_reward_whitelist"}`,arguments:[t.object(i),t.object(s)],typeArguments:[f]})}),t}async getBinStepConfigList(e){let t=await this._sdk.FullClient.getDynamicFields({parentId:e}),r=[],i=t.data.map(s=>s.objectId);return i.length>0&&(await this._sdk.FullClient.batchGetObjects(i,{showContent:!0})).forEach(u=>{let f={...(0,ee.getObjectFields)(u).value.fields};r.push(f)}),r}async getDlmmGlobalConfig(){let{dlmm_pool:e}=this._sdk.sdkOptions,{global_config_id:t}=(0,ee.getPackagerConfigs)(e);try{let r=await this._sdk.FullClient.getObject({id:t,options:{showContent:!0}}),i=(0,ee.getObjectFields)(r),s=i.reward_config.fields,u=s.reward_white_list?.fields?.contents?.map(f=>(0,ee.fixCoinType)(f.fields.key.fields.name,!1))||[];return{id:i.id.id,acl:{id:i.acl.fields.permissions.fields.id.id,size:i.acl.fields.permissions.fields.size},allowed_list:{id:i.allowed_list.fields.id.id,size:i.allowed_list.fields.size},denied_list:{id:i.denied_list.fields.id.id,size:i.denied_list.fields.size},bin_steps:{id:i.bin_steps.fields.id.id,size:i.bin_steps.fields.size},reward_white_list:u,blocked_position:{id:i.restriction.fields.blocked_position.fields.permissions.fields.id.id,size:i.restriction.fields.blocked_position.fields.permissions.fields.size},blocked_user:{id:i.restriction.fields.blocked_user.fields.permissions.fields.id.id,size:i.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),K("FetchError",r,{[ee.DETAILS_KEYS.METHOD_NAME]:"getBinStepConfigs",[ee.DETAILS_KEYS.REQUEST_PARAMS]:t})}}async fetchDlmmSdkConfigs(){let{dlmm_pool:e}=this._sdk.sdkOptions,t={registry_id:"",pools_id:"",global_config_id:"",versioned_id:"",admin_cap_id:"",partners_id:""},i=(await this._sdk.FullClient.getObject({id:e.package_id,options:{showContent:!0,showPreviousTransaction:!0}})).data?.previousTransaction;(await this._sdk.FullClient.getTransactionBlock({digest:i,options:{showEvents:!0}})).events?.forEach(f=>{let h=f.type,p=f.parsedJson;h.includes("versioned::InitEvent")&&(t.versioned_id=p.versioned),h.includes("partner::InitPartnerEvent")&&(t.partners_id=p.partners_id),h.includes("config::InitEvent")&&(t.global_config_id=p.config_id),h.includes("admin_cap::InitEvent")&&(t.admin_cap_id=p.admin_cap_id),h.includes("registry::RegistryEvent")&&(t.registry_id=p.pools_id)});let u=await this._sdk.FullClient.getObject({id:t.registry_id,options:{showContent:!0}}),d=(0,ee.getObjectFields)(u);return t.pools_id=d.pools.fields.id.id,t}};var Ie=class n extends Or.SdkWrapper{constructor(e){super(e),this._pool=new Be(this),this._position=new $e(this),this._swap=new ze(this),this._partner=new Ge(this),this._reward=new Xe(this),this._config=new Je(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(e){let{env:t="mainnet"}=e;return t==="mainnet"?n.createCustomSDK({...wi,...e}):n.createCustomSDK({...Ni,...e})}static createCustomSDK(e){return new n(e)}};var Un=Ie;0&&(module.exports={BASIS_POINT,BASIS_POINT_MAX,BIN_BOUND,BinUtils,CetusDlmmSDK,DEFAULT_MAX_WEIGHT,DEFAULT_MIN_WEIGHT,FEE_PRECISION,FeeUtils,IlmUtils,MAX_BIN_ID,MAX_BIN_PER_POSITION,MAX_FEE_RATE,MIN_BIN_ID,ONE,PoolModule,REWARD_PERIOD,REWARD_PERIOD_START_AT,SCALE_OFFSET,StrategyType,StrategyUtils,WeightUtils,dlmmMainnet,dlmmTestnet,generateRewardSchedule,getRouterModule,parseBinInfo,parseBinInfoList,parseCurrentRewardPeriodEmission,parseDlmmBasePool,parseDlmmPool,parseDlmmPosition,parseLiquidityShares,parsePartner,parsePoolTransactionInfo,parseRewardPeriodEmission,parseStrategyType,parsedDlmmPosFeeData,parsedDlmmPosRewardData,parsedSwapQuoteData,poolFilterEvenTypes,safeMulAmount});
|
|
2
|
+
/*! Bundled license information:
|
|
3
|
+
|
|
4
|
+
decimal.js/decimal.mjs:
|
|
5
|
+
(*!
|
|
6
|
+
* decimal.js v10.6.0
|
|
7
|
+
* An arbitrary-precision Decimal type for JavaScript.
|
|
8
|
+
* https://github.com/MikeMcl/decimal.js
|
|
9
|
+
* Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
|
|
10
|
+
* MIT Licence
|
|
11
|
+
*)
|
|
12
|
+
*/
|
|
13
|
+
//# sourceMappingURL=index.js.map
|