@cetusprotocol/dlmm-sdk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/.turbo/turbo-build.log +10423 -0
  2. package/README.md +646 -0
  3. package/dist/index.d.mts +1015 -0
  4. package/dist/index.d.ts +1015 -0
  5. package/dist/index.js +13 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +13 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/package.json +35 -0
  10. package/src/config/index.ts +2 -0
  11. package/src/config/mainnet.ts +25 -0
  12. package/src/config/testnet.ts +30 -0
  13. package/src/errors/errors.ts +40 -0
  14. package/src/index.ts +8 -0
  15. package/src/modules/configModule.ts +184 -0
  16. package/src/modules/index.ts +1 -0
  17. package/src/modules/partnerModule.ts +302 -0
  18. package/src/modules/poolModule.ts +578 -0
  19. package/src/modules/positionModule.ts +888 -0
  20. package/src/modules/rewardModule.ts +175 -0
  21. package/src/modules/swapModule.ts +129 -0
  22. package/src/sdk.ts +88 -0
  23. package/src/types/constants.ts +23 -0
  24. package/src/types/dlmm.ts +445 -0
  25. package/src/types/index.ts +2 -0
  26. package/src/utils/binUtils.ts +552 -0
  27. package/src/utils/feeUtils.ts +92 -0
  28. package/src/utils/index.ts +5 -0
  29. package/src/utils/parseData.ts +519 -0
  30. package/src/utils/strategyUtils.ts +121 -0
  31. package/src/utils/weightUtils.ts +510 -0
  32. package/tests/add_liquidity_bidask.test.ts +180 -0
  33. package/tests/add_liquidity_curve.test.ts +244 -0
  34. package/tests/add_liquidity_spot.test.ts +262 -0
  35. package/tests/bin.test.ts +80 -0
  36. package/tests/config.test.ts +51 -0
  37. package/tests/partner.test.ts +74 -0
  38. package/tests/pool.test.ts +174 -0
  39. package/tests/position.test.ts +76 -0
  40. package/tests/remove_liquidity.test.ts +137 -0
  41. package/tests/swap.test.ts +96 -0
  42. package/tests/tsconfig.json +26 -0
  43. package/tsconfig.json +5 -0
  44. package/tsup.config.ts +9 -0
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";var Or=Object.create;var Oe=Object.defineProperty;var Ir=Object.getOwnPropertyDescriptor;var Cr=Object.getOwnPropertyNames;var Tr=Object.getPrototypeOf,kr=Object.prototype.hasOwnProperty;var Rr=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),xr=(n,e)=>{for(var t in e)Oe(n,t,{get:e[t],enumerable:!0})},er=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Cr(e))!kr.call(n,i)&&i!==t&&Oe(n,i,{get:()=>e[i],enumerable:!(r=Ir(e,i))||r.enumerable});return n};var gi=(n,e,t)=>(t=n!=null?Or(Tr(n)):{},er(e||!n||!n.__esModule?Oe(t,"default",{value:n,enumerable:!0}):t,n)),Dr=n=>er(Oe({},"__esModule",{value:!0}),n);var Ie=Rr((nr,wi)=>{"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,w=c;w<_;w+=m)a=f(o,w,w+m,l),this.imuln(g),this.words[0]+a<67108864?this.words[0]+=a:this._iaddn(a);if(P!==0){var x=1;for(a=f(o,w,o.length,l),w=0;w<P;w++)x*=l;this.imuln(x),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 b=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],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=b[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],w=A[o];c="";var x=this.clone();for(x.negative=0;!x.isZero();){var F=x.modrn(w).toString(o);x=x.idivn(w),x.isZero()?c=F+c:c=b[a-F.length]+F+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 C(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 w=_>>>26,x=_&67108863,F=Math.min(a,o.length-1),L=Math.max(0,a-v.length+1);L<=F;L++){var K=a-L|0;m=v.words[K]|0,g=o.words[L]|0,M=m*g+x,w+=M/67108864|0,x=M&67108863}l.words[a]=x|0,_=w|0}return _!==0?l.words[a]=_|0:l.length--,l._strip()}var k=function(o,l,c){var m=o.words,g=l.words,M=c.words,P=0,_,a,w,x=m[0]|0,F=x&8191,L=x>>>13,K=m[1]|0,Y=K&8191,it=K>>>13,ae=m[2]|0,rt=ae&8191,st=ae>>>13,Li=m[3]|0,ut=Li&8191,dt=Li>>>13,qi=m[4]|0,ft=qi&8191,ct=qi>>>13,ji=m[5]|0,ht=ji&8191,pt=ji>>>13,Wi=m[6]|0,mt=Wi&8191,_t=Wi>>>13,Ui=m[7]|0,gt=Ui&8191,bt=Ui>>>13,Zi=m[8]|0,wt=Zi&8191,vt=Zi>>>13,Hi=m[9]|0,yt=Hi&8191,Mt=Hi>>>13,Qi=g[0]|0,Pt=Qi&8191,At=Qi>>>13,Ki=g[1]|0,St=Ki&8191,Bt=Ki>>>13,$i=g[2]|0,Et=$i&8191,Ot=$i>>>13,zi=g[3]|0,It=zi&8191,Ct=zi>>>13,Gi=g[4]|0,Tt=Gi&8191,kt=Gi>>>13,Vi=g[5]|0,Rt=Vi&8191,xt=Vi>>>13,Xi=g[6]|0,Dt=Xi&8191,Ft=Xi>>>13,Ji=g[7]|0,Nt=Ji&8191,Lt=Ji>>>13,Yi=g[8]|0,qt=Yi&8191,jt=Yi>>>13,tr=g[9]|0,Wt=tr&8191,Ut=tr>>>13;c.negative=o.negative^l.negative,c.length=19,_=Math.imul(F,Pt),a=Math.imul(F,At),a=a+Math.imul(L,Pt)|0,w=Math.imul(L,At);var Je=(P+_|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(Je>>>26)|0,Je&=67108863,_=Math.imul(Y,Pt),a=Math.imul(Y,At),a=a+Math.imul(it,Pt)|0,w=Math.imul(it,At),_=_+Math.imul(F,St)|0,a=a+Math.imul(F,Bt)|0,a=a+Math.imul(L,St)|0,w=w+Math.imul(L,Bt)|0;var Ye=(P+_|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(Ye>>>26)|0,Ye&=67108863,_=Math.imul(rt,Pt),a=Math.imul(rt,At),a=a+Math.imul(st,Pt)|0,w=Math.imul(st,At),_=_+Math.imul(Y,St)|0,a=a+Math.imul(Y,Bt)|0,a=a+Math.imul(it,St)|0,w=w+Math.imul(it,Bt)|0,_=_+Math.imul(F,Et)|0,a=a+Math.imul(F,Ot)|0,a=a+Math.imul(L,Et)|0,w=w+Math.imul(L,Ot)|0;var ti=(P+_|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(ti>>>26)|0,ti&=67108863,_=Math.imul(ut,Pt),a=Math.imul(ut,At),a=a+Math.imul(dt,Pt)|0,w=Math.imul(dt,At),_=_+Math.imul(rt,St)|0,a=a+Math.imul(rt,Bt)|0,a=a+Math.imul(st,St)|0,w=w+Math.imul(st,Bt)|0,_=_+Math.imul(Y,Et)|0,a=a+Math.imul(Y,Ot)|0,a=a+Math.imul(it,Et)|0,w=w+Math.imul(it,Ot)|0,_=_+Math.imul(F,It)|0,a=a+Math.imul(F,Ct)|0,a=a+Math.imul(L,It)|0,w=w+Math.imul(L,Ct)|0;var ei=(P+_|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(ei>>>26)|0,ei&=67108863,_=Math.imul(ft,Pt),a=Math.imul(ft,At),a=a+Math.imul(ct,Pt)|0,w=Math.imul(ct,At),_=_+Math.imul(ut,St)|0,a=a+Math.imul(ut,Bt)|0,a=a+Math.imul(dt,St)|0,w=w+Math.imul(dt,Bt)|0,_=_+Math.imul(rt,Et)|0,a=a+Math.imul(rt,Ot)|0,a=a+Math.imul(st,Et)|0,w=w+Math.imul(st,Ot)|0,_=_+Math.imul(Y,It)|0,a=a+Math.imul(Y,Ct)|0,a=a+Math.imul(it,It)|0,w=w+Math.imul(it,Ct)|0,_=_+Math.imul(F,Tt)|0,a=a+Math.imul(F,kt)|0,a=a+Math.imul(L,Tt)|0,w=w+Math.imul(L,kt)|0;var ii=(P+_|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(ii>>>26)|0,ii&=67108863,_=Math.imul(ht,Pt),a=Math.imul(ht,At),a=a+Math.imul(pt,Pt)|0,w=Math.imul(pt,At),_=_+Math.imul(ft,St)|0,a=a+Math.imul(ft,Bt)|0,a=a+Math.imul(ct,St)|0,w=w+Math.imul(ct,Bt)|0,_=_+Math.imul(ut,Et)|0,a=a+Math.imul(ut,Ot)|0,a=a+Math.imul(dt,Et)|0,w=w+Math.imul(dt,Ot)|0,_=_+Math.imul(rt,It)|0,a=a+Math.imul(rt,Ct)|0,a=a+Math.imul(st,It)|0,w=w+Math.imul(st,Ct)|0,_=_+Math.imul(Y,Tt)|0,a=a+Math.imul(Y,kt)|0,a=a+Math.imul(it,Tt)|0,w=w+Math.imul(it,kt)|0,_=_+Math.imul(F,Rt)|0,a=a+Math.imul(F,xt)|0,a=a+Math.imul(L,Rt)|0,w=w+Math.imul(L,xt)|0;var ri=(P+_|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(ri>>>26)|0,ri&=67108863,_=Math.imul(mt,Pt),a=Math.imul(mt,At),a=a+Math.imul(_t,Pt)|0,w=Math.imul(_t,At),_=_+Math.imul(ht,St)|0,a=a+Math.imul(ht,Bt)|0,a=a+Math.imul(pt,St)|0,w=w+Math.imul(pt,Bt)|0,_=_+Math.imul(ft,Et)|0,a=a+Math.imul(ft,Ot)|0,a=a+Math.imul(ct,Et)|0,w=w+Math.imul(ct,Ot)|0,_=_+Math.imul(ut,It)|0,a=a+Math.imul(ut,Ct)|0,a=a+Math.imul(dt,It)|0,w=w+Math.imul(dt,Ct)|0,_=_+Math.imul(rt,Tt)|0,a=a+Math.imul(rt,kt)|0,a=a+Math.imul(st,Tt)|0,w=w+Math.imul(st,kt)|0,_=_+Math.imul(Y,Rt)|0,a=a+Math.imul(Y,xt)|0,a=a+Math.imul(it,Rt)|0,w=w+Math.imul(it,xt)|0,_=_+Math.imul(F,Dt)|0,a=a+Math.imul(F,Ft)|0,a=a+Math.imul(L,Dt)|0,w=w+Math.imul(L,Ft)|0;var ni=(P+_|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(ni>>>26)|0,ni&=67108863,_=Math.imul(gt,Pt),a=Math.imul(gt,At),a=a+Math.imul(bt,Pt)|0,w=Math.imul(bt,At),_=_+Math.imul(mt,St)|0,a=a+Math.imul(mt,Bt)|0,a=a+Math.imul(_t,St)|0,w=w+Math.imul(_t,Bt)|0,_=_+Math.imul(ht,Et)|0,a=a+Math.imul(ht,Ot)|0,a=a+Math.imul(pt,Et)|0,w=w+Math.imul(pt,Ot)|0,_=_+Math.imul(ft,It)|0,a=a+Math.imul(ft,Ct)|0,a=a+Math.imul(ct,It)|0,w=w+Math.imul(ct,Ct)|0,_=_+Math.imul(ut,Tt)|0,a=a+Math.imul(ut,kt)|0,a=a+Math.imul(dt,Tt)|0,w=w+Math.imul(dt,kt)|0,_=_+Math.imul(rt,Rt)|0,a=a+Math.imul(rt,xt)|0,a=a+Math.imul(st,Rt)|0,w=w+Math.imul(st,xt)|0,_=_+Math.imul(Y,Dt)|0,a=a+Math.imul(Y,Ft)|0,a=a+Math.imul(it,Dt)|0,w=w+Math.imul(it,Ft)|0,_=_+Math.imul(F,Nt)|0,a=a+Math.imul(F,Lt)|0,a=a+Math.imul(L,Nt)|0,w=w+Math.imul(L,Lt)|0;var oi=(P+_|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(oi>>>26)|0,oi&=67108863,_=Math.imul(wt,Pt),a=Math.imul(wt,At),a=a+Math.imul(vt,Pt)|0,w=Math.imul(vt,At),_=_+Math.imul(gt,St)|0,a=a+Math.imul(gt,Bt)|0,a=a+Math.imul(bt,St)|0,w=w+Math.imul(bt,Bt)|0,_=_+Math.imul(mt,Et)|0,a=a+Math.imul(mt,Ot)|0,a=a+Math.imul(_t,Et)|0,w=w+Math.imul(_t,Ot)|0,_=_+Math.imul(ht,It)|0,a=a+Math.imul(ht,Ct)|0,a=a+Math.imul(pt,It)|0,w=w+Math.imul(pt,Ct)|0,_=_+Math.imul(ft,Tt)|0,a=a+Math.imul(ft,kt)|0,a=a+Math.imul(ct,Tt)|0,w=w+Math.imul(ct,kt)|0,_=_+Math.imul(ut,Rt)|0,a=a+Math.imul(ut,xt)|0,a=a+Math.imul(dt,Rt)|0,w=w+Math.imul(dt,xt)|0,_=_+Math.imul(rt,Dt)|0,a=a+Math.imul(rt,Ft)|0,a=a+Math.imul(st,Dt)|0,w=w+Math.imul(st,Ft)|0,_=_+Math.imul(Y,Nt)|0,a=a+Math.imul(Y,Lt)|0,a=a+Math.imul(it,Nt)|0,w=w+Math.imul(it,Lt)|0,_=_+Math.imul(F,qt)|0,a=a+Math.imul(F,jt)|0,a=a+Math.imul(L,qt)|0,w=w+Math.imul(L,jt)|0;var si=(P+_|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(si>>>26)|0,si&=67108863,_=Math.imul(yt,Pt),a=Math.imul(yt,At),a=a+Math.imul(Mt,Pt)|0,w=Math.imul(Mt,At),_=_+Math.imul(wt,St)|0,a=a+Math.imul(wt,Bt)|0,a=a+Math.imul(vt,St)|0,w=w+Math.imul(vt,Bt)|0,_=_+Math.imul(gt,Et)|0,a=a+Math.imul(gt,Ot)|0,a=a+Math.imul(bt,Et)|0,w=w+Math.imul(bt,Ot)|0,_=_+Math.imul(mt,It)|0,a=a+Math.imul(mt,Ct)|0,a=a+Math.imul(_t,It)|0,w=w+Math.imul(_t,Ct)|0,_=_+Math.imul(ht,Tt)|0,a=a+Math.imul(ht,kt)|0,a=a+Math.imul(pt,Tt)|0,w=w+Math.imul(pt,kt)|0,_=_+Math.imul(ft,Rt)|0,a=a+Math.imul(ft,xt)|0,a=a+Math.imul(ct,Rt)|0,w=w+Math.imul(ct,xt)|0,_=_+Math.imul(ut,Dt)|0,a=a+Math.imul(ut,Ft)|0,a=a+Math.imul(dt,Dt)|0,w=w+Math.imul(dt,Ft)|0,_=_+Math.imul(rt,Nt)|0,a=a+Math.imul(rt,Lt)|0,a=a+Math.imul(st,Nt)|0,w=w+Math.imul(st,Lt)|0,_=_+Math.imul(Y,qt)|0,a=a+Math.imul(Y,jt)|0,a=a+Math.imul(it,qt)|0,w=w+Math.imul(it,jt)|0,_=_+Math.imul(F,Wt)|0,a=a+Math.imul(F,Ut)|0,a=a+Math.imul(L,Wt)|0,w=w+Math.imul(L,Ut)|0;var ai=(P+_|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(ai>>>26)|0,ai&=67108863,_=Math.imul(yt,St),a=Math.imul(yt,Bt),a=a+Math.imul(Mt,St)|0,w=Math.imul(Mt,Bt),_=_+Math.imul(wt,Et)|0,a=a+Math.imul(wt,Ot)|0,a=a+Math.imul(vt,Et)|0,w=w+Math.imul(vt,Ot)|0,_=_+Math.imul(gt,It)|0,a=a+Math.imul(gt,Ct)|0,a=a+Math.imul(bt,It)|0,w=w+Math.imul(bt,Ct)|0,_=_+Math.imul(mt,Tt)|0,a=a+Math.imul(mt,kt)|0,a=a+Math.imul(_t,Tt)|0,w=w+Math.imul(_t,kt)|0,_=_+Math.imul(ht,Rt)|0,a=a+Math.imul(ht,xt)|0,a=a+Math.imul(pt,Rt)|0,w=w+Math.imul(pt,xt)|0,_=_+Math.imul(ft,Dt)|0,a=a+Math.imul(ft,Ft)|0,a=a+Math.imul(ct,Dt)|0,w=w+Math.imul(ct,Ft)|0,_=_+Math.imul(ut,Nt)|0,a=a+Math.imul(ut,Lt)|0,a=a+Math.imul(dt,Nt)|0,w=w+Math.imul(dt,Lt)|0,_=_+Math.imul(rt,qt)|0,a=a+Math.imul(rt,jt)|0,a=a+Math.imul(st,qt)|0,w=w+Math.imul(st,jt)|0,_=_+Math.imul(Y,Wt)|0,a=a+Math.imul(Y,Ut)|0,a=a+Math.imul(it,Wt)|0,w=w+Math.imul(it,Ut)|0;var li=(P+_|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(li>>>26)|0,li&=67108863,_=Math.imul(yt,Et),a=Math.imul(yt,Ot),a=a+Math.imul(Mt,Et)|0,w=Math.imul(Mt,Ot),_=_+Math.imul(wt,It)|0,a=a+Math.imul(wt,Ct)|0,a=a+Math.imul(vt,It)|0,w=w+Math.imul(vt,Ct)|0,_=_+Math.imul(gt,Tt)|0,a=a+Math.imul(gt,kt)|0,a=a+Math.imul(bt,Tt)|0,w=w+Math.imul(bt,kt)|0,_=_+Math.imul(mt,Rt)|0,a=a+Math.imul(mt,xt)|0,a=a+Math.imul(_t,Rt)|0,w=w+Math.imul(_t,xt)|0,_=_+Math.imul(ht,Dt)|0,a=a+Math.imul(ht,Ft)|0,a=a+Math.imul(pt,Dt)|0,w=w+Math.imul(pt,Ft)|0,_=_+Math.imul(ft,Nt)|0,a=a+Math.imul(ft,Lt)|0,a=a+Math.imul(ct,Nt)|0,w=w+Math.imul(ct,Lt)|0,_=_+Math.imul(ut,qt)|0,a=a+Math.imul(ut,jt)|0,a=a+Math.imul(dt,qt)|0,w=w+Math.imul(dt,jt)|0,_=_+Math.imul(rt,Wt)|0,a=a+Math.imul(rt,Ut)|0,a=a+Math.imul(st,Wt)|0,w=w+Math.imul(st,Ut)|0;var ui=(P+_|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(ui>>>26)|0,ui&=67108863,_=Math.imul(yt,It),a=Math.imul(yt,Ct),a=a+Math.imul(Mt,It)|0,w=Math.imul(Mt,Ct),_=_+Math.imul(wt,Tt)|0,a=a+Math.imul(wt,kt)|0,a=a+Math.imul(vt,Tt)|0,w=w+Math.imul(vt,kt)|0,_=_+Math.imul(gt,Rt)|0,a=a+Math.imul(gt,xt)|0,a=a+Math.imul(bt,Rt)|0,w=w+Math.imul(bt,xt)|0,_=_+Math.imul(mt,Dt)|0,a=a+Math.imul(mt,Ft)|0,a=a+Math.imul(_t,Dt)|0,w=w+Math.imul(_t,Ft)|0,_=_+Math.imul(ht,Nt)|0,a=a+Math.imul(ht,Lt)|0,a=a+Math.imul(pt,Nt)|0,w=w+Math.imul(pt,Lt)|0,_=_+Math.imul(ft,qt)|0,a=a+Math.imul(ft,jt)|0,a=a+Math.imul(ct,qt)|0,w=w+Math.imul(ct,jt)|0,_=_+Math.imul(ut,Wt)|0,a=a+Math.imul(ut,Ut)|0,a=a+Math.imul(dt,Wt)|0,w=w+Math.imul(dt,Ut)|0;var di=(P+_|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(di>>>26)|0,di&=67108863,_=Math.imul(yt,Tt),a=Math.imul(yt,kt),a=a+Math.imul(Mt,Tt)|0,w=Math.imul(Mt,kt),_=_+Math.imul(wt,Rt)|0,a=a+Math.imul(wt,xt)|0,a=a+Math.imul(vt,Rt)|0,w=w+Math.imul(vt,xt)|0,_=_+Math.imul(gt,Dt)|0,a=a+Math.imul(gt,Ft)|0,a=a+Math.imul(bt,Dt)|0,w=w+Math.imul(bt,Ft)|0,_=_+Math.imul(mt,Nt)|0,a=a+Math.imul(mt,Lt)|0,a=a+Math.imul(_t,Nt)|0,w=w+Math.imul(_t,Lt)|0,_=_+Math.imul(ht,qt)|0,a=a+Math.imul(ht,jt)|0,a=a+Math.imul(pt,qt)|0,w=w+Math.imul(pt,jt)|0,_=_+Math.imul(ft,Wt)|0,a=a+Math.imul(ft,Ut)|0,a=a+Math.imul(ct,Wt)|0,w=w+Math.imul(ct,Ut)|0;var fi=(P+_|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(fi>>>26)|0,fi&=67108863,_=Math.imul(yt,Rt),a=Math.imul(yt,xt),a=a+Math.imul(Mt,Rt)|0,w=Math.imul(Mt,xt),_=_+Math.imul(wt,Dt)|0,a=a+Math.imul(wt,Ft)|0,a=a+Math.imul(vt,Dt)|0,w=w+Math.imul(vt,Ft)|0,_=_+Math.imul(gt,Nt)|0,a=a+Math.imul(gt,Lt)|0,a=a+Math.imul(bt,Nt)|0,w=w+Math.imul(bt,Lt)|0,_=_+Math.imul(mt,qt)|0,a=a+Math.imul(mt,jt)|0,a=a+Math.imul(_t,qt)|0,w=w+Math.imul(_t,jt)|0,_=_+Math.imul(ht,Wt)|0,a=a+Math.imul(ht,Ut)|0,a=a+Math.imul(pt,Wt)|0,w=w+Math.imul(pt,Ut)|0;var ci=(P+_|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(ci>>>26)|0,ci&=67108863,_=Math.imul(yt,Dt),a=Math.imul(yt,Ft),a=a+Math.imul(Mt,Dt)|0,w=Math.imul(Mt,Ft),_=_+Math.imul(wt,Nt)|0,a=a+Math.imul(wt,Lt)|0,a=a+Math.imul(vt,Nt)|0,w=w+Math.imul(vt,Lt)|0,_=_+Math.imul(gt,qt)|0,a=a+Math.imul(gt,jt)|0,a=a+Math.imul(bt,qt)|0,w=w+Math.imul(bt,jt)|0,_=_+Math.imul(mt,Wt)|0,a=a+Math.imul(mt,Ut)|0,a=a+Math.imul(_t,Wt)|0,w=w+Math.imul(_t,Ut)|0;var hi=(P+_|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(hi>>>26)|0,hi&=67108863,_=Math.imul(yt,Nt),a=Math.imul(yt,Lt),a=a+Math.imul(Mt,Nt)|0,w=Math.imul(Mt,Lt),_=_+Math.imul(wt,qt)|0,a=a+Math.imul(wt,jt)|0,a=a+Math.imul(vt,qt)|0,w=w+Math.imul(vt,jt)|0,_=_+Math.imul(gt,Wt)|0,a=a+Math.imul(gt,Ut)|0,a=a+Math.imul(bt,Wt)|0,w=w+Math.imul(bt,Ut)|0;var pi=(P+_|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(pi>>>26)|0,pi&=67108863,_=Math.imul(yt,qt),a=Math.imul(yt,jt),a=a+Math.imul(Mt,qt)|0,w=Math.imul(Mt,jt),_=_+Math.imul(wt,Wt)|0,a=a+Math.imul(wt,Ut)|0,a=a+Math.imul(vt,Wt)|0,w=w+Math.imul(vt,Ut)|0;var mi=(P+_|0)+((a&8191)<<13)|0;P=(w+(a>>>13)|0)+(mi>>>26)|0,mi&=67108863,_=Math.imul(yt,Wt),a=Math.imul(yt,Ut),a=a+Math.imul(Mt,Wt)|0,w=Math.imul(Mt,Ut);var _i=(P+_|0)+((a&8191)<<13)|0;return P=(w+(a>>>13)|0)+(_i>>>26)|0,_i&=67108863,M[0]=Je,M[1]=Ye,M[2]=ti,M[3]=ei,M[4]=ii,M[5]=ri,M[6]=ni,M[7]=oi,M[8]=si,M[9]=ai,M[10]=li,M[11]=ui,M[12]=di,M[13]=fi,M[14]=ci,M[15]=hi,M[16]=pi,M[17]=mi,M[18]=_i,P!==0&&(M[19]=P,c.length++),c};Math.imul||(k=C);function R(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 w=g-a,x=v.words[w]|0,F=o.words[a]|0,L=x*F,K=L&67108863;M=M+(L/67108864|0)|0,K=K+P|0,P=K&67108863,M=M+(K>>>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 T(v,o,l){return R(v,o,l)}i.prototype.mulTo=function(o,l){var c,m=this.length+o.length;return this.length===10&&o.length===10?c=k(this,o,l):m<63?c=C(this,o,l):m<1024?c=R(this,o,l):c=T(this,o,l),c};function I(v,o){this.x=v,this.y=o}I.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},I.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},I.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]]},I.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/_),w=Math.sin(2*Math.PI/_),x=0;x<g;x+=_)for(var F=a,L=w,K=0;K<P;K++){var Y=c[x+K],it=m[x+K],ae=c[x+K+P],rt=m[x+K+P],st=F*ae-L*rt;rt=F*rt+L*ae,ae=st,c[x+K]=Y+ae,m[x+K]=it+rt,c[x+K+P]=Y-ae,m[x+K+P]=it-rt,K!==_&&(st=a*F-w*L,L=a*L+w*F,F=st)}},I.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},I.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}},I.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},I.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)},I.prototype.stub=function(o){for(var l=new Array(o),c=0;c<o;c++)l[c]=0;return l},I.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),w=new Array(m),x=new Array(m),F=new Array(m),L=c.words;L.length=m,this.convert13b(o.words,o.length,P,m),this.convert13b(l.words,l.length,w,m),this.transform(P,M,_,a,m,g),this.transform(w,M,x,F,m,g);for(var K=0;K<m;K++){var Y=_[K]*x[K]-a[K]*F[K];a[K]=_[K]*F[K]+a[K]*x[K],_[K]=Y}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),T(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 w=0;for(a=this.length-1;a>=0&&(w!==0||a>=m);a--){var x=this.words[a]|0;this.words[a]=w<<26-g|x>>>g,w=x&P}return _&&w!==0&&(_.words[_.length++]=w),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 w=0;w<a.length;w++)a.words[w]=0}var x=m.clone()._ishlnsubmul(g,1,_);x.negative===0&&(m=x,a&&(a.words[_]=1));for(var F=_-1;F>=0;F--){var L=(m.words[g.length+F]|0)*67108864+(m.words[g.length+F-1]|0);for(L=Math.min(L/M|0,67108863),m._ishlnsubmul(g,L,F);m.negative!==0;)L--,m.negative=0,m._ishlnsubmul(g,1,F),m.isZero()||(m.negative^=1);a&&(a.words[F]=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(),w=l.clone();!l.isZero();){for(var x=0,F=1;(l.words[0]&F)===0&&x<26;++x,F<<=1);if(x>0)for(l.iushrn(x);x-- >0;)(m.isOdd()||g.isOdd())&&(m.iadd(a),g.isub(w)),m.iushrn(1),g.iushrn(1);for(var L=0,K=1;(c.words[0]&K)===0&&L<26;++L,K<<=1);if(L>0)for(c.iushrn(L);L-- >0;)(M.isOdd()||P.isOdd())&&(M.iadd(a),P.isub(w)),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,w=1;(c.words[0]&w)===0&&a<26;++a,w<<=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 x;return l.cmpn(1)===0?x=m:x=g,x.cmpn(0)<0&&x.iadd(o),x},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 G(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 $(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()}$.prototype._tmp=function(){var o=new i(null);return o.words=new Array(Math.ceil(this.n/13)),o},$.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},$.prototype.split=function(o,l){o.iushrn(this.n,0,l)},$.prototype.imulK=function(o){return o.imul(this.k)};function nt(){$.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}r(nt,$),nt.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},nt.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(){$.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}r(at,$);function Gt(){$.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}r(Gt,$);function Jt(){$.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}r(Jt,$),Jt.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 nt;else if(o==="p224")l=new at;else if(o==="p192")l=new Gt;else if(o==="p25519")l=new Jt;else throw new Error("Unknown prime "+o);return z[o]=l,l};function G(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}G.prototype._verify1=function(o){t(o.negative===0,"red works only with positives"),t(o.red,"red works only with red numbers")},G.prototype._verify2=function(o,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")},G.prototype.imod=function(o){return this.prime?this.prime.ireduce(o)._forceRed(this):(h(o,o.umod(this.m)._forceRed(this)),o)},G.prototype.neg=function(o){return o.isZero()?o.clone():this.m.sub(o)._forceRed(this)},G.prototype.add=function(o,l){this._verify2(o,l);var c=o.add(l);return c.cmp(this.m)>=0&&c.isub(this.m),c._forceRed(this)},G.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},G.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)},G.prototype.isub=function(o,l){this._verify2(o,l);var c=o.isub(l);return c.cmpn(0)<0&&c.iadd(this.m),c},G.prototype.shl=function(o,l){return this._verify1(o),this.imod(o.ushln(l))},G.prototype.imul=function(o,l){return this._verify2(o,l),this.imod(o.imul(l))},G.prototype.mul=function(o,l){return this._verify2(o,l),this.imod(o.mul(l))},G.prototype.isqr=function(o){return this.imul(o,o.clone())},G.prototype.sqr=function(o){return this.mul(o,o)},G.prototype.sqrt=function(o){if(o.isZero())return o.clone();var 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 w=this.pow(a,m),x=this.pow(o,m.addn(1).iushrn(1)),F=this.pow(o,m),L=g;F.cmp(M)!==0;){for(var K=F,Y=0;K.cmp(M)!==0;Y++)K=K.redSqr();t(Y<L);var it=this.pow(w,new i(1).iushln(L-Y-1));x=x.redMul(it),w=it.redSqr(),F=F.redMul(w),L=Y}return x},G.prototype.invm=function(o){var l=o._invmp(this.m);return l.negative!==0?(l.negative=0,this.imod(l).redNeg()):this.imod(l)},G.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 w=l.words[g],x=a-1;x>=0;x--){var F=w>>x&1;if(M!==m[0]&&(M=this.sqr(M)),F===0&&P===0){_=0;continue}P<<=1,P|=F,_++,!(_!==c&&(g!==0||x!==0))&&(M=this.mul(M,m[P]),_=0,P=0)}a=26}return M},G.prototype.convertTo=function(o){var l=o.umod(this.m);return l===o?l.clone():l},G.prototype.convertFrom=function(o){var l=o.clone();return l.red=null,l},i.mont=function(o){return new ot(o)};function ot(v){G.call(this,v),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new 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(ot,G),ot.prototype.convertTo=function(o){return this.imod(o.ushln(this.shift))},ot.prototype.convertFrom=function(o){var l=this.imod(o.mul(this.rinv));return l.red=null,l},ot.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)},ot.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)},ot.prototype.invm=function(o){var l=this.imod(o._invmp(this.m).mul(this.r2));return l._forceRed(this)}})(typeof wi>"u"||wi,nr)});var Wn={};xr(Wn,{BASIS_POINT:()=>Yt,BASIS_POINT_MAX:()=>ge,BIN_BOUND:()=>he,BinUtils:()=>q,CetusDlmmSDK:()=>Ee,DEFAULT_MAX_WEIGHT:()=>qe,DEFAULT_MIN_WEIGHT:()=>je,FEE_PRECISION:()=>Ue,FeeUtils:()=>Ri,MAX_BIN_ID:()=>Tn,MAX_BIN_PER_POSITION:()=>se,MAX_FEE_RATE:()=>We,MIN_BIN_ID:()=>Cn,ONE:()=>Ze,PoolModule:()=>Se,REWARD_PERIOD:()=>kn,REWARD_PERIOD_START_AT:()=>Rn,SCALE_OFFSET:()=>Q,StrategyType:()=>Le,StrategyUtils:()=>we,WeightUtils:()=>zt,default:()=>jn,dlmmMainnet:()=>bi,dlmmTestnet:()=>Di,generateRewardSchedule:()=>Nn,getRouterModule:()=>ki,parseBinInfo:()=>Ei,parseBinInfoList:()=>Bi,parseCurrentRewardPeriodEmission:()=>qn,parseDlmmBasePool:()=>Si,parseDlmmPool:()=>Me,parseDlmmPosition:()=>Qe,parseLiquidityShares:()=>Dn,parsePartner:()=>He,parsePoolTransactionInfo:()=>Ti,parseRewardPeriodEmission:()=>Ln,parseStrategyType:()=>Fn,parsedDlmmPosFeeData:()=>Oi,parsedDlmmPosRewardData:()=>Ii,parsedSwapQuoteData:()=>Ci,poolFilterEvenTypes:()=>yr,safeMulAmount:()=>ie});module.exports=Dr(Wn);var Er=require("@cetusprotocol/common-sdk");var ir=require("@cetusprotocol/common-sdk"),bi={env:"mainnet",full_rpc_url:ir.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 Pe=require("@mysten/sui/transactions"),V=require("@cetusprotocol/common-sdk");var rr=require("@cetusprotocol/common-sdk");var pe=class extends rr.BaseError{constructor(e,t,r){super(e,t||"UnknownError",r)}static isDlmmErrorCode(e,t){return this.isErrorCode(e,t)}},Z=(n,e,t)=>{let r={...t,stack:e instanceof Error?e.stack:void 0};throw e instanceof Error?new pe(e.message,n,r):new pe(e,n,r)};var H=require("@cetusprotocol/common-sdk"),vr=gi(Ie());var me=9e15,fe=1e9,vi="0123456789abcdef",ke="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Re="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",yi={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-me,maxE:me,crypto:!1},lr,oe,U=!0,De="[DecimalError] ",de=De+"Invalid argument: ",ur=De+"Precision limit exceeded",dr=De+"crypto unavailable",fr="[object Decimal]",$t=Math.floor,Zt=Math.pow,Fr=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Nr=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Lr=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,cr=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,ee=1e7,W=7,qr=9007199254740991,jr=ke.length-1,Mi=Re.length-1,E={toStringTag:fr};E.absoluteValue=E.abs=function(){var n=new this.constructor(this);return n.s<0&&(n.s=1),N(n)};E.ceil=function(){return N(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(de+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=Wr(r,gr(r,t)),r.precision=n,r.rounding=e,N(oe==2||oe==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,b=p.constructor;if(!p.isFinite()||p.isZero())return new b(p);for(U=!1,s=p.s*Zt(p.s*p,1/3),!s||Math.abs(s)==1/0?(t=Qt(p.d),n=p.e,(s=(n-t.length+1)%3)&&(t+=s==1||s==-2?"0":"00"),s=Zt(t,1/3),n=$t((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 b(t),r.s=p.s):r=new b(s.toString()),u=(n=b.precision)+3;;)if(d=r,f=d.times(d).times(d),h=f.plus(p),r=et(h.plus(p).times(d),h.plus(f),u+2,1),Qt(d.d).slice(0,u)===(t=Qt(r.d)).slice(0,u))if(t=t.slice(u-3,u+1),t=="9999"||!i&&t=="4999"){if(!i&&(N(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")&&(N(r,n+1,1),e=!r.times(r).times(r).eq(p));break}return U=!0,N(r,n,b.rounding,e)};E.decimalPlaces=E.dp=function(){var n,e=this.d,t=NaN;if(e){if(n=e.length-1,t=(n-$t(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 et(this,new this.constructor(n))};E.dividedToIntegerBy=E.divToInt=function(n){var e=this,t=e.constructor;return N(et(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 N(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/Ne(4,n)).toString()):(n=16,e="2.3283064365386962890625e-10"),s=_e(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 N(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=_e(s,2,i,i,!0);else{n=1.4*Math.sqrt(r),n=n>16?16:n|0,i=i.times(1/Ne(5,n)),i=_e(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,N(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,et(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()?re(e,r,i):new e(0):new e(NaN):n.isZero()?re(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,U=!1,t=t.times(t).minus(1).sqrt().plus(t),U=!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,U=!1,t=t.times(t).plus(1).sqrt().plus(t),U=!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?N(new s(i),n,e,!0):(s.precision=t=r-i.e,i=et(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=re(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,b=p.precision,y=p.rounding;if(h.isFinite()){if(h.isZero())return new p(h);if(h.abs().eq(1)&&b+4<=Mi)return u=re(p,b+4,y).times(.25),u.s=h.s,u}else{if(!h.s)return new p(NaN);if(b+4<=Mi)return u=re(p,b+4,y).times(.5),u.s=h.s,u}for(p.precision=d=b+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(U=!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)),U=!0,N(u,p.precision=b,p.rounding=y,!0)};E.isFinite=function(){return!!this.d};E.isInteger=E.isInt=function(){return!!this.d&&$t(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,b=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(U=!1,d=b+A,u=ue(h,d),r=e?xe(p,d+10):ue(n,d),f=et(u,r,d,1),ve(f.d,i=b,y))do if(d+=10,u=ue(h,d),r=e?xe(p,d+10):ue(n,d),f=et(u,r,d,1),!s){+Qt(f.d).slice(i+1,i+15)+1==1e14&&(f=N(f,b+1,0));break}while(ve(f.d,i+=10,y));return U=!0,N(f,b,y)};E.minus=E.sub=function(n){var e,t,r,i,s,u,d,f,h,p,b,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 U?N(n,d,f):n}if(t=$t(n.e/W),p=$t(A.e/W),h=h.slice(),s=p-t,s){for(b=s<0,b?(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,b=r<u,b&&(u=r),r=0;r<u;r++)if(h[r]!=y[r]){b=h[r]<y[r];break}s=0}for(b&&(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]=ee-1;--h[i],h[r]+=ee}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=Fe(h,t),U?N(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]?N(new r(t),r.precision,r.rounding):(U=!1,r.modulo==9?(e=et(t,n.abs(),0,3,1),e.s*=n.s):e=et(t,n,0,r.modulo,1),e=e.times(n),U=!0,t.minus(e))};E.naturalExponential=E.exp=function(){return Pi(this)};E.naturalLogarithm=E.ln=function(){return ue(this)};E.negated=E.neg=function(){var n=new this.constructor(this);return n.s=-n.s,N(n)};E.plus=E.add=function(n){var e,t,r,i,s,u,d,f,h,p,b=this,y=b.constructor;if(n=new y(n),!b.d||!n.d)return!b.s||!n.s?n=new y(NaN):b.d||(n=new y(n.d||b.s===n.s?b:NaN)),n;if(b.s!=n.s)return n.s=-n.s,b.minus(n);if(h=b.d,p=n.d,d=y.precision,f=y.rounding,!h[0]||!p[0])return p[0]||(n=new y(b)),U?N(n,d,f):n;if(s=$t(b.e/W),r=$t(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)/ee|0,h[i]%=ee;for(e&&(h.unshift(e),++r),u=h.length;h[--u]==0;)h.pop();return n.d=h,n.e=Fe(h,r),U?N(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(de+n);return t.d?(e=hr(t.d),n&&t.e+1>e&&(e=t.e+1)):e=NaN,e};E.round=function(){var n=this,e=n.constructor;return N(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=Zr(r,gr(r,t)),r.precision=n,r.rounding=e,N(oe>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(U=!1,h=Math.sqrt(+u),h==0||h==1/0?(e=Qt(d),(e.length+f)%2==0&&(e+="0"),h=Math.sqrt(e),f=$t((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(et(u,s,t+2,1)).times(.5),Qt(s.d).slice(0,t)===(e=Qt(r.d)).slice(0,t))if(e=e.slice(t-3,t+1),e=="9999"||!i&&e=="4999"){if(!i&&(N(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")&&(N(r,f+1,1),n=!r.times(r).eq(u));break}return U=!0,N(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=et(t,new r(1).minus(t.times(t)).sqrt(),n+10,0),r.precision=n,r.rounding=e,N(oe==2||oe==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,b=p.constructor,y=p.d,A=(n=new b(n)).d;if(n.s*=p.s,!y||!y[0]||!A||!A[0])return new b(!n.s||y&&!y[0]&&!A||A&&!A[0]&&!y?NaN:!y||!A?n.s/0:n.s*0);for(t=$t(p.e/W)+$t(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%ee|0,e=d/ee|0;s[i]=(s[i]+e)%ee|0}for(;!s[--u];)s.pop();return e?++t:s.shift(),n.d=s,n.e=Fe(s,t),U?N(n,b.precision,b.rounding):n};E.toBinary=function(n,e){return Ai(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:(Vt(n,0,fe),e===void 0?e=r.rounding:Vt(e,0,8),N(t,n+t.e+1,e))};E.toExponential=function(n,e){var t,r=this,i=r.constructor;return n===void 0?t=ne(r,!0):(Vt(n,0,fe),e===void 0?e=i.rounding:Vt(e,0,8),r=N(new i(r),n+1,e),t=ne(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=ne(i):(Vt(n,0,fe),e===void 0?e=s.rounding:Vt(e,0,8),r=N(new s(i),n+i.e+1,e),t=ne(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,b,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=hr(B)-A.e-1,u=s%W,e.d[0]=Zt(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(de+d);n=d.gt(e)?s>0?e:h:d}for(U=!1,d=new S(Qt(B)),p=S.precision,S.precision=s=B.length*W*2;b=et(d,e,0,1,1),i=t.plus(b.times(r)),i.cmp(n)!=1;)t=r,r=i,i=h,h=f.plus(b.times(i)),f=i,i=e,e=d.minus(b.times(i)),d=i;return i=et(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=et(h,r,s,1).minus(A).abs().cmp(et(f,t,s,1).minus(A).abs())<1?[h,r]:[f,t],S.precision=p,U=!0,y};E.toHexadecimal=E.toHex=function(n,e){return Ai(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:Vt(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]?(U=!1,t=et(t,n,0,e,1).times(n),U=!0,N(t)):(n.s=t.s,t=n),t};E.toNumber=function(){return+this};E.toOctal=function(n,e){return Ai(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(Zt(+d,h));if(d=new f(d),d.eq(1))return d;if(r=f.precision,s=f.rounding,n.eq(1))return N(d,r,s);if(e=$t(n.e/W),e>=n.d.length-1&&(t=h<0?-h:h)<=qr)return i=pr(f,d,t,r),n.s<0?new f(1).div(i):N(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=Zt(+d,h),e=t==0||!isFinite(t)?$t(h*(Math.log("0."+Qt(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):(U=!1,f.rounding=d.s=1,t=Math.min(12,(e+"").length),i=Pi(n.times(ue(d,r+t)),r),i.d&&(i=N(i,r+5,1),ve(i.d,r,s)&&(e=r+10,i=N(Pi(n.times(ue(d,e+t)),e),e+5,1),+Qt(i.d).slice(r+1,r+15)+1==1e14&&(i=N(i,r+1,0)))),i.s=u,U=!0,f.rounding=s,N(i,r,s))};E.toPrecision=function(n,e){var t,r=this,i=r.constructor;return n===void 0?t=ne(r,r.e<=i.toExpNeg||r.e>=i.toExpPos):(Vt(n,1,fe),e===void 0?e=i.rounding:Vt(e,0,8),r=N(new i(r),n,e),t=ne(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):(Vt(n,1,fe),e===void 0?e=r.rounding:Vt(e,0,8)),N(new r(t),n,e)};E.toString=function(){var n=this,e=n.constructor,t=ne(n,n.e<=e.toExpNeg||n.e>=e.toExpPos);return n.isNeg()&&!n.isZero()?"-"+t:t};E.truncated=E.trunc=function(){return N(new this.constructor(this),this.e+1,1)};E.valueOf=E.toJSON=function(){var n=this,e=n.constructor,t=ne(n,n.e<=e.toExpNeg||n.e>=e.toExpPos);return n.isNeg()?"-"+t:t};function Qt(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+=le(t)),s+=r;u=n[e],r=u+"",t=W-r.length,t&&(s+=le(t))}else if(u===0)return"0";for(;u%10===0;)u/=10;return s+u}function Vt(n,e,t){if(n!==~~n||n<e||n>t)throw Error(de+n)}function ve(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=Zt(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)==Zt(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)==Zt(10,e-3)-1,u}function Ce(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]+=vi.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 Wr(n,e){var t,r,i;if(e.isZero())return e;r=e.d.length,r<32?(t=Math.ceil(r/3),i=(1/Ne(4,t)).toString()):(t=16,i="2.3283064365386962890625e-10"),n.precision+=t,e=_e(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 et=(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,b,y,A,B,S,C,k,R,T,I,z,$,nt,at,Gt,Jt,G,ot,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=ee,A=W,p=$t(r.e/A)-$t(i.e/A)),G=c.length,Gt=l.length,k=new v(o),R=k.d=[],b=0;c[b]==(l[b]||0);b++);if(c[b]>(l[b]||0)&&p--,s==null?($=s=v.precision,u=v.rounding):d?$=s+(r.e-i.e)+1:$=s,$<0)R.push(1),B=!0;else{if($=$/A+2|0,b=0,G==1){for(y=0,c=c[0],$++;(b<Gt||y)&&$--;b++)nt=y*f+(l[b]||0),R[b]=nt/c|0,y=nt%c|0;B=y||b<Gt}else{for(y=f/(c[0]+1)|0,y>1&&(c=n(c,y,f),l=n(l,y,f),G=c.length,Gt=l.length),at=G,T=l.slice(0,G),I=T.length;I<G;)T[I++]=0;ot=c.slice(),ot.unshift(0),Jt=c[0],c[1]>=f/2&&++Jt;do y=0,h=e(c,T,G,I),h<0?(z=T[0],G!=I&&(z=z*f+(T[1]||0)),y=z/Jt|0,y>1?(y>=f&&(y=f-1),S=n(c,y,f),C=S.length,I=T.length,h=e(S,T,C,I),h==1&&(y--,t(S,G<C?ot:c,C,f))):(y==0&&(h=y=1),S=c.slice()),C=S.length,C<I&&S.unshift(0),t(T,S,I,f),h==-1&&(I=T.length,h=e(c,T,G,I),h<1&&(y++,t(T,G<I?ot:c,I,f))),I=T.length):h===0&&(y++,T=[0]),R[b++]=y,h&&T[0]?T[I++]=l[at]||0:(T=[l[at]],I=1);while((at++<Gt||T[0]!==void 0)&&$--);B=T[0]!==void 0}R[0]||R.shift()}if(A==1)k.e=p,lr=B;else{for(b=1,y=R[0];y>=10;y/=10)b++;k.e=b+p*A-1,N(k,d?s+k.e+1:s,u,B)}return k}})();function N(n,e,t,r){var i,s,u,d,f,h,p,b,y,A=n.constructor;t:if(e!=null){if(b=n.d,!b)return n;for(i=1,d=b[0];d>=10;d/=10)i++;if(s=e-i,s<0)s+=W,u=e,p=b[y=0],f=p/Zt(10,i-u-1)%10|0;else if(y=Math.ceil((s+1)/W),d=b.length,y>=d)if(r){for(;d++<=y;)b.push(0);p=f=0,i=1,s%=W,u=s-W+1}else break t;else{for(p=d=b[y],i=1;d>=10;d/=10)i++;s%=W,u=s-W+i,f=u<0?0:p/Zt(10,i-u-1)%10|0}if(r=r||e<0||b[y+1]!==void 0||(u<0?p:p%Zt(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/Zt(10,i-u):0:b[y-1])%10&1||t==(n.s<0?8:7)),e<1||!b[0])return b.length=0,h?(e-=n.e+1,b[0]=Zt(10,(W-e%W)%W),n.e=-e||0):b[0]=n.e=0,n;if(s==0?(b.length=y,d=1,y--):(b.length=y+1,d=Zt(10,W-s),b[y]=u>0?(p/Zt(10,i-u)%Zt(10,u)|0)*d:0),h)for(;;)if(y==0){for(s=1,u=b[0];u>=10;u/=10)s++;for(u=b[0]+=d,d=1;u>=10;u/=10)d++;s!=d&&(n.e++,b[0]==ee&&(b[0]=1));break}else{if(b[y]+=d,b[y]!=ee)break;b[y--]=0,d=1}for(s=b.length;b[--s]===0;)b.pop()}return U&&(n.e>A.maxE?(n.d=null,n.e=NaN):n.e<A.minE&&(n.e=0,n.d=[0])),n}function ne(n,e,t){if(!n.isFinite())return _r(n);var r,i=n.e,s=Qt(n.d),u=s.length;return e?(t&&(r=t-u)>0?s=s.charAt(0)+"."+s.slice(1)+le(r):u>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(n.e<0?"e":"e+")+n.e):i<0?(s="0."+le(-i-1)+s,t&&(r=t-u)>0&&(s+=le(r))):i>=u?(s+=le(i+1-u),t&&(r=t-i-1)>0&&(s=s+"."+le(r))):((r=i+1)<u&&(s=s.slice(0,r)+"."+s.slice(r)),t&&(r=t-u)>0&&(i+1===u&&(s+="."),s+=le(r))),s}function Fe(n,e){var t=n[0];for(e*=W;t>=10;t/=10)e++;return e}function xe(n,e,t){if(e>jr)throw U=!0,t&&(n.precision=t),Error(ur);return N(new n(ke),e,1,!0)}function re(n,e,t){if(e>Mi)throw Error(ur);return N(new n(Re),e,t,!0)}function hr(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 le(n){for(var e="";n--;)e+="0";return e}function pr(n,e,t,r){var i,s=new n(1),u=Math.ceil(r/W+4);for(U=!1;;){if(t%2&&(s=s.times(e),sr(s.d,u)&&(i=!0)),t=$t(t/2),t===0){t=s.d.length-1,i&&s.d[t]===0&&++s.d[t];break}e=e.times(e),sr(e.d,u)}return U=!0,s}function or(n){return n.d[n.d.length-1]&1}function mr(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 Pi(n,e){var t,r,i,s,u,d,f,h=0,p=0,b=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?(U=!1,f=B):f=e,d=new y(.03125);n.e>-2;)n=n.times(d),b+=5;for(r=Math.log(Zt(2,b))/Math.LN10*2+5|0,f+=r,t=s=u=new y(1),y.precision=f;;){if(s=N(s.times(n),f,1),t=t.times(++p),d=u.plus(et(s,t,f,1)),Qt(d.d).slice(0,f)===Qt(u.d).slice(0,f)){for(i=b;i--;)u=N(u.times(u),f,1);if(e==null)if(h<3&&ve(u.d,f-r,A,h))y.precision=f+=10,t=s=d=new y(1),p=0,h++;else return N(u,y.precision=B,A,U=!0);else return y.precision=B,u}u=d}}function ue(n,e){var t,r,i,s,u,d,f,h,p,b,y,A=1,B=10,S=n,C=S.d,k=S.constructor,R=k.rounding,T=k.precision;if(S.s<0||!C||!C[0]||!S.e&&C[0]==1&&C.length==1)return new k(C&&!C[0]?-1/0:S.s!=1?NaN:C?0:S);if(e==null?(U=!1,p=T):p=e,k.precision=p+=B,t=Qt(C),r=t.charAt(0),Math.abs(s=S.e)<15e14){for(;r<7&&r!=1||r==1&&t.charAt(1)>3;)S=S.times(n),t=Qt(S.d),r=t.charAt(0),A++;s=S.e,r>1?(S=new k("0."+t),s++):S=new k(r+"."+t.slice(1))}else return h=xe(k,p+2,T).times(s+""),S=ue(new k(r+"."+t.slice(1)),p-B).plus(h),k.precision=T,e==null?N(S,T,R,U=!0):S;for(b=S,f=u=S=et(S.minus(1),S.plus(1),p,1),y=N(S.times(S),p,1),i=3;;){if(u=N(u.times(y),p,1),h=f.plus(et(u,new k(i),p,1)),Qt(h.d).slice(0,p)===Qt(f.d).slice(0,p))if(f=f.times(2),s!==0&&(f=f.plus(xe(k,p+2,T).times(s+""))),f=et(f,new k(A),p,1),e==null)if(ve(f.d,p-B,R,d))k.precision=p+=B,h=u=S=et(b.minus(1),b.plus(1),p,1),y=N(S.times(S),p,1),i=d=1;else return N(f,k.precision=T,R,U=!0);else return k.precision=T,f;f=h,i+=2}}function _r(n){return String(n.s*n.s/0)}function Te(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),U&&(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 Ur(n,e){var t,r,i,s,u,d,f,h,p;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),cr.test(e))return Te(n,e)}else if(e==="Infinity"||e==="NaN")return+e||(n.s=NaN),n.e=NaN,n.d=null,n;if(Nr.test(e))t=16,e=e.toLowerCase();else if(Fr.test(e))t=2;else if(Lr.test(e))t=8;else throw Error(de+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=pr(r,new r(t),s,s*2)),h=Ce(e,t,ee),p=h.length-1,s=p;h[s]===0;--s)h.pop();return s<0?new r(n.s*0):(n.e=Fe(h,p),n.d=h,U=!1,u&&(n=et(n,i,d*4)),f&&(n=n.times(Math.abs(f)<54?Zt(2,f):ye.pow(2,f))),U=!0,n)}function Zr(n,e){var t,r=e.d.length;if(r<3)return e.isZero()?e:_e(n,2,e,e);t=1.4*Math.sqrt(r),t=t>16?16:t|0,e=e.times(1/Ne(5,t)),e=_e(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 _e(n,e,t,r,i){var s,u,d,f,h=1,p=n.precision,b=Math.ceil(p/W);for(U=!1,f=t.times(t),d=new n(r);;){if(u=et(d.times(f),new n(e++*e++),p,1),d=i?r.plus(u):r.minus(u),r=et(u.times(f),new n(e++*e++),p,1),u=d.plus(r),u.d[b]!==void 0){for(s=b;u.d[s]===d.d[s]&&s--;);if(s==-1)break}s=d,d=r,r=u,u=s,h++}return U=!0,u.d.length=b+1,u}function Ne(n,e){for(var t=n;--e;)t*=n;return t}function gr(n,e){var t,r=e.s<0,i=re(n,n.precision,1),s=i.times(.5);if(e=e.abs(),e.lte(s))return oe=r?4:1,e;if(t=e.divToInt(i),t.isZero())oe=r?3:2;else{if(e=e.minus(t.times(i)),e.lte(s))return oe=or(t)?r?2:3:r?4:1,e;oe=or(t)?r?1:4:r?3:2}return e.minus(i).abs()}function Ai(n,e,t,r){var i,s,u,d,f,h,p,b,y,A=n.constructor,B=t!==void 0;if(B?(Vt(t,1,fe),r===void 0?r=A.rounding:Vt(r,0,8)):(t=A.precision,r=A.rounding),!n.isFinite())p=_r(n);else{for(p=ne(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=Ce(ne(y),10,i),y.e=y.d.length),b=Ce(p,10,i),s=f=b.length;b[--f]==0;)b.pop();if(!b[0])p=B?"0p+0":"0";else{if(u<0?s--:(n=new A(n),n.d=b,n.e=s,n=et(n,y,t,r,0,i),b=n.d,s=n.e,h=lr),u=b[t],d=i/2,h=h||b[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&&b[t-1]&1||r===(n.s<0?8:7)),b.length=t,h)for(;++b[--t]>i-1;)b[t]=0,t||(++s,b.unshift(1));for(f=b.length;!b[f-1];--f);for(u=0,p="";u<f;u++)p+=vi.charAt(b[u]);if(B){if(f>1)if(e==16||e==8){for(u=e==16?4:3,--f;f%u;f++)p+="0";for(b=Ce(p,i,e),f=b.length;!b[f-1];--f);for(u=1,p="1.";u<f;u++)p+=vi.charAt(b[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 sr(n,e){if(n.length>e)return n.length=e,!0}function Hr(n){return new this(n).abs()}function Qr(n){return new this(n).acos()}function Kr(n){return new this(n).acosh()}function $r(n,e){return new this(n).plus(e)}function zr(n){return new this(n).asin()}function Gr(n){return new this(n).asinh()}function Vr(n){return new this(n).atan()}function Xr(n){return new this(n).atanh()}function Jr(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=re(this,s,1).times(e.s>0?.25:.75),t.s=n.s):!e.d||n.isZero()?(t=e.s<0?re(this,r,i):new this(0),t.s=n.s):!n.d||e.isZero()?(t=re(this,s,1).times(.5),t.s=n.s):e.s<0?(this.precision=s,this.rounding=1,t=this.atan(et(n,e,s,1)),e=re(this,s,1),this.precision=r,this.rounding=i,t=n.s<0?t.minus(e):t.plus(e)):t=this.atan(et(n,e,s,1)),t}function Yr(n){return new this(n).cbrt()}function tn(n){return N(n=new this(n),n.e+1,2)}function en(n,e,t){return new this(n).clamp(e,t)}function rn(n){if(!n||typeof n!="object")throw Error(De+"Object expected");var e,t,r,i=n.defaults===!0,s=["precision",1,fe,"rounding",0,8,"toExpNeg",-me,0,"toExpPos",0,me,"maxE",0,me,"minE",-me,0,"modulo",0,9];for(e=0;e<s.length;e+=3)if(t=s[e],i&&(this[t]=yi[t]),(r=n[t])!==void 0)if($t(r)===r&&r>=s[e+1]&&r<=s[e+2])this[t]=r;else throw Error(de+t+": "+r);if(t="crypto",i&&(this[t]=yi[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(dr);else this[t]=!1;else throw Error(de+t+": "+r);return this}function nn(n){return new this(n).cos()}function on(n){return new this(n).cosh()}function br(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,ar(s)){h.s=s.s,U?!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++;U?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 Te(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),cr.test(s)?Te(h,s):Ur(h,s);if(f==="bigint")return s<0?(s=-s,h.s=-1):h.s=1,Te(h,s.toString());throw Error(de+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=rn,i.clone=br,i.isDecimal=ar,i.abs=Hr,i.acos=Qr,i.acosh=Kr,i.add=$r,i.asin=zr,i.asinh=Gr,i.atan=Vr,i.atanh=Xr,i.atan2=Jr,i.cbrt=Yr,i.ceil=tn,i.clamp=en,i.cos=nn,i.cosh=on,i.div=sn,i.exp=an,i.floor=ln,i.hypot=un,i.ln=dn,i.log=fn,i.log10=hn,i.log2=cn,i.max=pn,i.min=mn,i.mod=_n,i.mul=gn,i.pow=bn,i.random=wn,i.round=vn,i.sign=yn,i.sin=Mn,i.sinh=Pn,i.sqrt=An,i.sub=Sn,i.sum=Bn,i.tan=En,i.tanh=On,i.trunc=In,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 sn(n,e){return new this(n).div(e)}function an(n){return new this(n).exp()}function ln(n){return N(n=new this(n),n.e+1,3)}function un(){var n,e,t=new this(0);for(U=!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 U=!0,new this(1/0);t=e}return U=!0,t.sqrt()}function ar(n){return n instanceof ye||n&&n.toStringTag===fr||!1}function dn(n){return new this(n).ln()}function fn(n,e){return new this(n).log(e)}function cn(n){return new this(n).log(2)}function hn(n){return new this(n).log(10)}function pn(){return mr(this,arguments,-1)}function mn(){return mr(this,arguments,1)}function _n(n,e){return new this(n).mod(e)}function gn(n,e){return new this(n).mul(e)}function bn(n,e){return new this(n).pow(e)}function wn(n){var e,t,r,i,s=0,u=new this(1),d=[];if(n===void 0?n=this.precision:Vt(n,1,fe),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(dr);else for(;s<r;)d[s++]=Math.random()*1e7|0;for(r=d[--s],n%=W,r&&n&&(i=Zt(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 vn(n){return N(n=new this(n),n.e+1,this.rounding)}function yn(n){return n=new this(n),n.d?n.d[0]?n.s:0*n.s:n.s||NaN}function Mn(n){return new this(n).sin()}function Pn(n){return new this(n).sinh()}function An(n){return new this(n).sqrt()}function Sn(n,e){return new this(n).sub(e)}function Bn(){var n=0,e=arguments,t=new this(e[n]);for(U=!1;t.s&&++n<e.length;)t=t.plus(e[n]);return U=!0,N(t,this.precision,this.rounding)}function En(n){return new this(n).tan()}function On(n){return new this(n).tanh()}function In(n){return N(n=new this(n),n.e+1,1)}E[Symbol.for("nodejs.util.inspect.custom")]=E.toString;E[Symbol.toStringTag]="Decimal";var ye=E.constructor=br(yi);ke=new ye(ke);Re=new ye(Re);var D=ye;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 se=1e3,Cn=-443636,Tn=443636,ge=1e4,qe=2e3,je=200,he=443636n,We=1e8,Ue=1e9,Yt=1e4,kn=604800,Rn=1747627200;var J=gi(Ie());var xn=new J.default(524288),Q=64,Ze=new J.default(1).shln(Q),wr=new J.default(2).pow(new J.default(128)).sub(new J.default(1)),q=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,b)=>(0,j.d)(p).plus(b.amount_a),(0,j.d)(0)).toFixed(0),amount_b:h.reduce((p,b)=>(0,j.d)(p).plus(b.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,b=(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:b})}),{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,D.ROUND_FLOOR),d=(0,j.d)(t).div(s).mul(i).toFixed(0,D.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,D.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(Q))).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(Q)).toFixed(0)}static getAmountsFromLiquidity(e,t,r,i){if((0,j.d)(i).isZero()&&Z("LiquiditySupplyIsZero","Liquidity supply is zero"),(0,j.d)(r).gt((0,j.d)(i))&&Z("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,D.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,D.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 D(t).div(new D(1e4));return new D(1).add(new D(r)).pow(new D(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 D(t).div(new D(1e4)),s=new D(e).log().dividedBy(new D(1).add(i).log());return(r?s.floor():s.ceil()).toNumber()}static getPricePerLamport(e,t,r){return new D(r).mul(new D(10**(t-e))).toString()}static getPriceFromLamport(e,t,r){return new D(r).div(new D(10**(t-e))).toString()}static getReversePrice(e){return new D(1).div(e).toString()}static getQPriceFromId(e,t){let r=new J.default(t).shln(Q).div(new J.default(1e4)),i=Ze.add(r);return n.pow(i,new J.default(e)).toString()}static getPricePerLamportFromQPrice(e){return j.MathUtil.fromX64(new J.default(e)).toString()}static pow(e,t){let r=t.isNeg();if(t.isZero())return Ze;if(t=r?t.abs():t,t.gt(xn))return new J.default(0);let i=e,s=Ze;return i.gte(s)&&(i=wr.div(i),r=!r),t.and(new J.default(1)).isZero()||(s=s.mul(i).shrn(Q)),i=i.mul(i).shrn(Q),t.and(new J.default(2)).isZero()||(s=s.mul(i).shrn(Q)),i=i.mul(i).shrn(Q),t.and(new J.default(4)).isZero()||(s=s.mul(i).shrn(Q)),i=i.mul(i).shrn(Q),t.and(new J.default(8)).isZero()||(s=s.mul(i).shrn(Q)),i=i.mul(i).shrn(Q),t.and(new J.default(16)).isZero()||(s=s.mul(i).shrn(Q)),i=i.mul(i).shrn(Q),t.and(new J.default(32)).isZero()||(s=s.mul(i).shrn(Q)),i=i.mul(i).shrn(Q),t.and(new J.default(64)).isZero()||(s=s.mul(i).shrn(Q)),i=i.mul(i).shrn(Q),t.and(new J.default(128)).isZero()||(s=s.mul(i).shrn(Q)),i=i.mul(i).shrn(Q),t.and(new J.default(256)).isZero()||(s=s.mul(i).shrn(Q)),i=i.mul(i).shrn(Q),t.and(new J.default(512)).isZero()||(s=s.mul(i).shrn(Q)),i=i.mul(i).shrn(Q),t.and(new J.default(1024)).isZero()||(s=s.mul(i).shrn(Q)),i=i.mul(i).shrn(Q),t.and(new J.default(2048)).isZero()||(s=s.mul(i).shrn(Q)),i=i.mul(i).shrn(Q),t.and(new J.default(4096)).isZero()||(s=s.mul(i).shrn(Q)),i=i.mul(i).shrn(Q),t.and(new J.default(8192)).isZero()||(s=s.mul(i).shrn(Q)),i=i.mul(i).shrn(Q),t.and(new J.default(16384)).isZero()||(s=s.mul(i).shrn(Q)),i=i.mul(i).shrn(Q),t.and(new J.default(32768)).isZero()||(s=s.mul(i).shrn(Q)),i=i.mul(i).shrn(Q),t.and(new J.default(65536)).isZero()||(s=s.mul(i).shrn(Q)),i=i.mul(i).shrn(Q),t.and(new J.default(131072)).isZero()||(s=s.mul(i).shrn(Q)),i=i.mul(i).shrn(Q),t.and(new J.default(262144)).isZero()||(s=s.mul(i).shrn(Q)),s.isZero()?new J.default(0):(r&&(s=wr.div(s)),s)}static binScore(e){let t=BigInt(e)+he;return(t<0n||t>he*2n)&&Z("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)-he;return(t<-he||t>he)&&Z("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 D("18446744073709551615").log(10).div(new D(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,D.ROUND_UP);return console.log("getBinShift Options:",{active_id:e,bin_shift:d}),Number(d)}};var Xt=require("@mysten/sui/bcs");function Si(n){try{let e=n.parsedJson;return{id:e.pool_id,bin_step:Number(e.bin_step),coin_type_a:(0,H.fixCoinType)(e.coin_type_a,!1),coin_type_b:(0,H.fixCoinType)(e.coin_type_b,!1)}}catch(e){return Z("ParseError",e,{[H.DETAILS_KEYS.METHOD_NAME]:"parseDlmmBasePool",[H.DETAILS_KEYS.REQUEST_PARAMS]:n})}}function Me(n){try{let e=(0,H.getObjectFields)(n),t=(0,H.getObjectType)(n),r=(0,H.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(b=>{let y=b.fields.current_emission_rate,A=H.MathUtil.fromX64(new vr.default(y)),B=Math.floor(A.toNumber()*60*60*24).toString();return{reward_coin:(0,H.fixCoinType)(b.fields.reward_coin.fields.name,!1),emissions_per_second:A.toString(),emissions_per_day:B,period_emission_rates:{id:b.fields.period_emission_rates.fields.id.id,size:b.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,H.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,H.fixCoinType)(r.type_arguments[0],!1),coin_type_b:(0,H.fixCoinType)(r.type_arguments[1],!1),pool_type:t,index:Number(e.index),bin_manager:i,variable_parameters:h,active_id:(0,H.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),Z("ParseError",e,{[H.DETAILS_KEYS.METHOD_NAME]:"parseDlmmPool",[H.DETAILS_KEYS.REQUEST_PARAMS]:n})}}function He(n){let e=(0,H.getObjectFields)(n),t=(0,H.getObjectType)(n),r=(0,H.extractStructTagFromType)(t);return{id:e.id.id,name:e.name,ref_fee_rate:(0,H.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 Qe(n){try{let e=(0,H.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,H.asIntN)(BigInt(e.lower_bin_id.fields.bits)),upper_bin_id:(0,H.asIntN)(BigInt(e.upper_bin_id.fields.bits)),liquidity_shares:e.liquidity_shares,description:e.description,coin_type_a:(0,H.fixCoinType)(e.coin_type_a,!1),coin_type_b:(0,H.fixCoinType)(e.coin_type_b,!1)}}catch(e){return console.log("\u{1F680} ~ parseDlmmPosition ~ error:",e),Z("ParseError",e,{[H.DETAILS_KEYS.METHOD_NAME]:"parseDlmmPosition",[H.DETAILS_KEYS.REQUEST_PARAMS]:n})}}function Dn(n,e,t,r){let i=n.map((d,f)=>{let h=t+f,p=q.getPricePerLamportFromBinId(h,e);if(h===r.bin_id){let{amount_a:A,amount_b:B}=q.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=q.getAmountBFromLiquidity(d);return{bin_id:h,amount_a:"0",amount_b:A,liquidity:d,price_per_lamport:p}}let b=q.getQPriceFromId(h,e),y=q.getAmountAFromLiquidity(d,b);return{bin_id:h,amount_a:y,amount_b:"0",liquidity:d,price_per_lamport:p}}),s=i.reduce((d,f)=>d.add(new D(f.amount_a)),new D(0)).toFixed(0),u=i.reduce((d,f)=>d.add(new D(f.amount_b)),new D(0)).toFixed(0);return{bins:i,amount_a:s,amount_b:u}}function Bi(n){try{let e=Xt.bcs.struct("BinAmount",{id:Xt.bcs.struct("I32",{bits:Xt.bcs.u32()}),amount_a:Xt.bcs.u64(),amount_b:Xt.bcs.u64(),price:Xt.bcs.u128(),liquidity_supply:Xt.bcs.u128(),rewards_growth_global:Xt.bcs.vector(Xt.bcs.u128()),fee_a_growth_global:Xt.bcs.u128(),fee_b_growth_global:Xt.bcs.u128()});return Xt.bcs.vector(e).parse(Uint8Array.from(n.results[0].returnValues[0][0])).map(r=>({bin_id:(0,H.asIntN)(BigInt(r.id.bits)),amount_a:r.amount_a,amount_b:r.amount_b,liquidity:r.liquidity_supply,price_per_lamport:q.getPricePerLamportFromQPrice(r.price)}))}catch(e){return console.log("\u{1F680} ~ parseBinInfo ~ error:",e),[]}}function Ei(n){try{return{bin_id:(0,H.asIntN)(BigInt(n.id.fields.bits)),amount_a:n.amount_a,amount_b:n.amount_b,liquidity:n.liquidity_supply,price_per_lamport:q.getPricePerLamportFromQPrice(n.price)}}catch(e){return console.log("\u{1F680} ~ parseBinInfo ~ error:",e),Z("ParseError",e,{[H.DETAILS_KEYS.METHOD_NAME]:"parseBinInfo",[H.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 Ii(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,H.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 Ci(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:b,from:y,target:A}=i,B=b.map(C=>({bin_id:C.bin_id.bits,in_amount:C.amount_in,out_amount:C.amount_out,fee:C.fee,var_fee_rate:C.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,H.fixCoinType)(y.name,!1),to_coin_type:(0,H.fixCoinType)(A.name,!1)}}}function Fn(n){switch(n){case 0:return 0;case 1:return 1;case 2:return 2}}var yr=["RemoveLiquidityEvent","SwapEvent","AddLiquidityEvent","ClosePositionEvent"];function Ti(n,e,t,r){let i=[],{timestampMs:s,events:u}=n;return u?.forEach((d,f)=>{let{name:h,address:p}=(0,H.extractStructTagFromType)(d.type);if(yr.includes(h)&&p===t&&r===d.parsedJson.pool){let b={tx:d.id.txDigest,sender:d.sender,type:d.type,block_time:s||"0",index:`${e}_${f}`,parsed_json:d.parsedJson};i.push(b)}}),i}function Nn(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 Ln(n,e,t,r){let i=[];for(let s=e;s<=t;s+=r){let u=n.findLast(d=>(0,H.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 qn(n){if(n.length===0)return;let e=new Date().getTime()/1e3,t=n.findLast(r=>(0,H.d)(e).gte(r.time));return t||n[n.length-1]}function ie(n,e){let t=n.mul(e);if(t.gt(0)&&t.lt(1))throw new pe(`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 tt=require("@cetusprotocol/common-sdk");var zt=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,tt.d)(0));if(u.cmp((0,tt.d)(0))!=1)throw Error("Invalid parameters");return{bins:i.map(f=>{let h=q.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 b=(0,tt.d)(f.weight).div(u),y=ie((0,tt.d)(t),b).toString(),A="0",B=q.getQPriceFromId(f.bin_id,r),S=q.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=q.getPricePerLamportFromBinId(h.bin_id,t),b=new D(h.weight).div(p);return f.add(b)}},new D(0));if(u.cmp(new D(0))!=1)throw Error("Invalid parameters");return{bins:i.map(f=>{let h=q.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 D(f.weight).div(h).div(u),A=ie((0,tt.d)(r),y).toString(),B="0",S=q.getQPriceFromId(f.bin_id,t),C=q.getLiquidity(A,B,S);return{bin_id:f.bin_id,amount_a:A,amount_b:B,price_per_lamport:h,liquidity:C}}}),amount_a:r,amount_b:"0"}}static toAmountBothSide(e,t,r,i,s,u,d){let f=!(0,tt.d)(r).isZero()&&(0,tt.d)(i).isZero(),h=(0,tt.d)(r).isZero()&&!(0,tt.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(b=>b.bin_id===e);if(p.length===1){let{totalWeightA:b,totalWeightB:y,activeWeightA:A,activeWeightB:B}=n.calculateTotalWeights(t,d,e,p[0],s,u,f?"a":h?"b":void 0),S=new D(r.toString()).div(b),C=new D(i.toString()).div(y),k=d.map(I=>{let z=q.getPricePerLamportFromBinId(I.bin_id,t);if(I.bin_id<e||I.bin_id===e&&h){let ot=ie(C,new D(I.weight)),v="0",o=q.getQPriceFromId(I.bin_id,t),l=q.getLiquidity(v,ot.toString(),o);return{bin_id:I.bin_id,amount_a:"0",amount_b:ot.toString(),price_per_lamport:z,liquidity:l}}if(I.bin_id>e||I.bin_id===e&&f){let ot=new D(I.weight).div(z),v=ie(S,new D(ot)),o="0",l=q.getQPriceFromId(I.bin_id,t),c=q.getLiquidity(v.toString(),o,l);return{bin_id:I.bin_id,amount_a:v.toString(),amount_b:"0",price_per_lamport:z,liquidity:c}}let $=ie(S,A),nt=ie(C,B),at=$.toString(),Gt=nt.toString(),Jt=q.getQPriceFromId(I.bin_id,t),G=q.getLiquidity(at,Gt,Jt);return{bin_id:I.bin_id,amount_a:at,amount_b:Gt,price_per_lamport:z,liquidity:G}}),R=k.reduce((I,z)=>(0,tt.d)(I).add((0,tt.d)(z.amount_a)),(0,tt.d)(0)).toString(),T=k.reduce((I,z)=>(0,tt.d)(I).add((0,tt.d)(z.amount_b)),(0,tt.d)(0)).toString();return{bins:k,amount_a:R,amount_b:T}}else{let{totalWeightA:b,totalWeightB:y}=n.calculateTotalWeights(t,d,e),A=new D(r.toString()).div(b),B=new D(i.toString()).div(y),S=d.map(R=>{let T=q.getPricePerLamportFromBinId(R.bin_id,t);if(R.bin_id<e){let I=ie(B,new D(R.weight));return{bin_id:R.bin_id,amount_a:"0",amount_b:I.toString(),price_per_lamport:T}}else{let I=new D(R.weight).div(T),z=ie(A,I);return{bin_id:R.bin_id,amount_a:z.toString(),amount_b:"0",price_per_lamport:T}}}),C=S.reduce((R,T)=>(0,tt.d)(R).add((0,tt.d)(T.amount_a)),(0,tt.d)(0)).toString(),k=S.reduce((R,T)=>(0,tt.d)(R).add((0,tt.d)(T.amount_b)),(0,tt.d)(0)).toString();return{bins:S,amount_a:C,amount_b:k}}}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),b=(0,tt.d)(0);i?b=h.isZero()?new D(1):new D(r).div(h):b=p.isZero()?new D(1):new D(r).div(p);let y=ie(b,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,tt.d)(q.getPricePerLamportFromBinId(r,e)),h=(0,tt.d)(0),p=(0,tt.d)(0);if(s&&u&&i&&!d)if((0,tt.d)(s).isZero()&&(0,tt.d)(u).isZero())h=new D(i.weight).div(f.mul(new D(2))),p=new D(i.weight).div(new D(2));else{let A=new D(s.toString()),B=new D(u.toString());(0,tt.d)(s).isZero()||(h=new D(i.weight).div(f.add(B.div(A)))),(0,tt.d)(u).isZero()||(p=new D(i.weight).div(new D(1).add(f.mul(A).div(B))))}let b=h,y=p;return t.forEach(A=>{if((A.bin_id<r||d==="b")&&(y=y.add(new D(A.weight))),A.bin_id>r||d==="a"){let B=q.getPricePerLamportFromBinId(A.bin_id,e),S=new D(A.weight).div(B);b=b.add(S)}}),{totalWeightA:b,totalWeightB:y,activeWeightA:h,activeWeightB:p}}};var we=class{static toAmountsBothSideByStrategy(e,t,r,i,s,u,d,f,h){switch(h){case 0:{let p=zt.toWeightSpotBalanced(r,i);return zt.toAmountBothSide(e,t,s,u,d,f,p)}case 1:{let p=zt.toWeightCurve(r,i,e);return zt.toAmountBothSide(e,t,s,u,d,f,p)}case 2:{let p=zt.toWeightBidAsk(r,i,e);return zt.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=zt.toWeightSpotBalanced(d,f);return zt.autoFillCoinByWeight(e,t,r,i,s,u,p)}case 1:{let p=zt.toWeightCurve(d,f,e);return zt.autoFillCoinByWeight(e,t,r,i,s,u,p)}case 2:{let p=zt.toWeightBidAsk(d,f,e);return zt.autoFillCoinByWeight(e,t,r,i,s,u,p)}}}};var Ht=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,Ht.d)(i).gt(0)?(0,Ht.d)(t).mul(s).pow(2).mul(i).add(99999999999).div(1e11).toFixed(0):"0"}static calculateCompositionFee(e,t){let r=(0,Ht.d)(e).mul(t);return(0,Ht.d)(r).mul((0,Ht.d)(1e9).add(t)).div((0,Ht.d)(1e9).pow(2)).toFixed(0)}static calculateProtocolFee(e,t){return(0,Ht.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,Ht.d)(e.liquidity||"0").eq((0,Ht.d)(0)))return{fees_a:"0",fees_b:"0"};let{bin_step:s,base_factor:u}=r,d=q.getQPriceFromId(e.bin_id,s),f=q.getLiquidity(t.amount_a,t.amount_b,d),{amount_a:h,amount_b:p}=q.calculateOutByShare({bin_id:e.bin_id,liquidity:(0,Ht.d)(e.liquidity).add(f).toFixed(0),amount_a:(0,Ht.d)(e.amount_a).add(t.amount_a).toFixed(0),amount_b:(0,Ht.d)(e.amount_b).add(t.amount_b).toFixed(0),price_per_lamport:e.price_per_lamport},f),b=(0,Ht.d)(s).mul(u),y=n.getVariableFee(i),A=(0,Ht.d)(b).add(y).toFixed(0);(0,Ht.d)(A).gt(1e8)&&(A=1e8.toString());let B="0",S="0";return(0,Ht.d)(h).gt(t.amount_a)&&(B=n.calculateCompositionFee(h,A)),(0,Ht.d)(p).gt(t.amount_b)&&(S=n.calculateCompositionFee(p,A)),{fees_a:B,fees_b:S}}};var Mr=require("@mysten/sui/client"),xi=require("@mysten/sui/utils"),Ae=require("@mysten/sui/bcs"),Se=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=Si(h);i.data.push(p)}),s&&this._sdk.updateCache(`${r.package_id}_getPoolImmutables`,i.data)}catch(d){return Z("FetchError",d,{[V.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=Me(u),f=`${d.id}_getDlmmPool`;this._sdk.updateCache(f,d),r.data.push(d)}}catch(s){return Z("FetchError",s,{[V.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=q.binScore(t),[f,h]=q.resolveBinPosition(d),b=(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=Ei(b);return this._sdk.updateCache(s,y),y}catch{return{bin_id:t,amount_a:"0",amount_b:"0",liquidity:"0",price_per_lamport:q.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 Pe.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,xi.normalizeSuiAddress)("0x0")});return Ae.bcs.struct("FeeRate",{base_fee_rate:Ae.bcs.u64(),var_fee_rate:Ae.bcs.u64(),total_fee_rate:Ae.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 Pe.Transaction;p.moveCall({target:`${t.published_at}::pool::fetch_bins`,arguments:[p.object(r),p.pure.vector("u32",f?[Number((0,V.asUintN)(BigInt(f)))]:[]),p.pure.u64(u)],typeArguments:[i,s]});let b=await this._sdk.FullClient.devInspectTransactionBlock({transactionBlock:p,sender:(0,xi.normalizeSuiAddress)("0x0")}),y=Bi(b);d.push(...y),f=y.length>0?y[y.length-1].bin_id:void 0,h=y.length===u}return d.sort((p,b)=>p.bin_id-b.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,V.createFullClient)(new Mr.SuiClient({url:i})):d=s;let f={data:[],has_next_page:!1},h=50,p=t,b=t.limit||10;do{let y=await d.queryTransactionBlocksByPage({ChangedObject:e},{...p,limit:50},r);y.data.forEach((A,B)=>{let S=Ti(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<b&&f.has_next_page);return f.data.length>b&&(f.data=f.data.slice(0,b),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=Me(i),u=`${s.id}_getDlmmPool`;this._sdk.updateCache(u,s),t.push(s)}}catch(r){return Z("FetchError",r,{[V.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=Me(s);return this._sdk.updateCache(r,u),u}catch(r){return Z("FetchError",r,{[V.DETAILS_KEYS.METHOD_NAME]:"getPool",[V.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:b,decimals_b:y,strategy_type:A,use_bin_infos:B,base_factor:S}=e,C,k,R,T=u;if(d==="coin_a")C=q.getBinIdFromPrice(h,t,!1,b,y),k=q.getBinIdFromPrice(p,t,!0,b,y),R=q.getBinIdFromPrice(f,t,!0,b,y);else{C=q.getBinIdFromPrice((0,V.d)(1).div(p).toString(),t,!1,b,y),k=q.getBinIdFromPrice((0,V.d)(1).div(h).toString(),t,!0,b,y),R=q.getBinIdFromPrice((0,V.d)(1).div(f).toString(),t,!1,b,y);let $={amount_a:u.amount_b,amount_b:u.amount_a,active_id:R,bin_step:t,lower_bin_id:C,upper_bin_id:k,amount_a_in_active_bin:"0",amount_b_in_active_bin:"0",strategy_type:e.strategy_type};T=this.sdk.Position.calculateAddLiquidityInfo($)}let z={bin_step:t,url:r,coin_type_a:i,coin_type_b:s,bin_infos:T,lower_bin_id:C,upper_bin_id:k,active_id:R,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 Pe.Transaction;let{registry_id:p,global_config_id:b,versioned_id:y}=(0,V.getPackagerConfigs)(r),A=await this._sdk.FullClient.fetchCoinMetadata(d);A?.id||Z("FetchError",new Error(`coin_a_metadata not found: ${d}`),{[V.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityPayload",[V.DETAILS_KEYS.REQUEST_PARAMS]:e});let B=await this._sdk.FullClient.fetchCoinMetadata(f);B?.id||Z("FetchError",new Error(`coin_b_metadata not found: ${f}`),{[V.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityPayload",[V.DETAILS_KEYS.REQUEST_PARAMS]:e});let[S,C]=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,V.asUintN)(BigInt(h)))),t.pure.string(u||""),t.object(b),t.object(y),t.object(V.CLOCK_ADDRESS)],typeArguments:[d,f]});return t.moveCall({target:`${r.published_at}::registry::destroy_receipt`,arguments:[t.object(S),C,t.object(y)],typeArguments:[d,f]}),C}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:b,strategy_type:y,use_bin_infos:A}=e,{registry_id:B,global_config_id:S,versioned_id:C}=(0,V.getPackagerConfigs)(t),k=new Pe.Transaction;(0,V.isSortedSymbols)((0,V.fixCoinType)(d,!1),(0,V.fixCoinType)(f,!1))&&Z("InvalidCoinTypeSequence",new Error("invalid coin type sequence"),{[V.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityPayload",[V.DETAILS_KEYS.REQUEST_PARAMS]:e});let R=b-p+1;R>1e3&&Z("InvalidBinWidth",new Error("Width is too large"),{[V.DETAILS_KEYS.METHOD_NAME]:"openPosition",[V.DETAILS_KEYS.REQUEST_PARAMS]:e}),(await this._sdk.FullClient.fetchCoinMetadata(d))?.id||Z("FetchError",new Error(`coin_a_metadata not found: ${d}`),{[V.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityPayload",[V.DETAILS_KEYS.REQUEST_PARAMS]:e}),(await this._sdk.FullClient.fetchCoinMetadata(f))?.id||Z("FetchError",new Error(`coin_b_metadata not found: ${f}`),{[V.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityPayload",[V.DETAILS_KEYS.REQUEST_PARAMS]:e}),console.log("\u{1F680} ~ createPoolAndAddLiquidityPayload ~ option:",{...e,width:R});let $={pool_id:await this.createPoolPayload({active_id:u,bin_step:r,base_factor:i,coin_type_a:d,coin_type_b:f},k),bin_infos:h,coin_type_a:d,coin_type_b:f,lower_bin_id:p,upper_bin_id:b,active_id:u,strategy_type:y,use_bin_infos:A,max_price_slippage:0,bin_step:r};return this.sdk.Position.addLiquidityPayload($,k),k}};var Pr=require("@cetusprotocol/common-sdk"),Di={env:"testnet",full_rpc_url:Pr.FullRpcUrlTestnet,dlmm_pool:{package_id:"0x05a79a247dc4c0daf0c03912cc2f14ebb3d0ca925482c3c09f516b16825bfc45",published_at:"0x534b3ca6b921257b33db4d0d0ac5b4f37c1eb15c22c5a55b38faba8d9f91b1c3",version:1,config:{registry_id:"0xcb49fbeebeb778fcae261c3a9fad8abe7e329ac0f86ef458e0bd5b587b0ad858",pools_id:"0x7fc11580586ea9f0941be9973345ebf82cf5c479353b865a22e59cd720b8bf04",global_config_id:"0xac39b660d54aadaaef08b17605d0c91c102797be18b00b590647321f11948c35",versioned_id:"0xc1d8eae3c5e6b5322136bbe71c3d348b1061695cf199e9c4d5efd1139b294edb",admin_cap_id:"0x570ce0b84182892b8af58fd74307a144aa36b330141bfa01d0f0c1978d2325a8",partners_id:"0xd7833b08e9637f4431f6a69dad8f6d0f9f3b09c16387b33ac527411df0f99d12"}},dlmm_router:{package_id:"0xe2c57dabc1ab2c48d17b50e418d77312c29d1f98594bdf5bffb643b07231ac09",published_at:"0x3249405dc05e570e642bc8029f8ce0800ee1e7589e8988af8acc6730fd83dbf5",version:1},faucet:{package_id:"0x14a71d857b34677a7d57e0feb303df1adb515a37780645ab763d42ce8d1a5e48",published_at:"0x14a71d857b34677a7d57e0feb303df1adb515a37780645ab763d42ce8d1a5e48",version:1}};var O=require("@cetusprotocol/common-sdk"),ce=require("@mysten/sui/transactions"),Ar=require("@mysten/sui/utils");var Ke=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(Qe(i))})}catch(r){console.log("\u{1F680} ~ PositionModule ~ getOwnerPositionList ~ error:",r),Z("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 Qe(t)}catch(t){return console.log("\u{1F680} ~ PositionModule ~ getPosition ~ error:",t),Z("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 ce.Transaction;let[p,b]=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(b,u,t);return t.transferObjects([y,A],this.sdk.getSenderAddress()),t}updatePositionFeeAndRewards(e,t){let{dlmm_pool:r}=this.sdk.sdkOptions,{versioned_id:i,global_config_id:s}=(0,O.getPackagerConfigs)(r),{pool_id:u,position_id:d,coin_type_a:f,coin_type_b:h}=e;return t.moveCall({target:`${r.published_at}::pool::update_position_fee_and_rewards`,arguments:[t.object(u),t.pure.id(d),t.object(s),t.object(i),t.object(O.CLOCK_ADDRESS)],typeArguments:[f,h]}),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 ce.Transaction,e.forEach(u=>{let{pool_id:d,position_id:f,reward_coins:h,coin_type_a:p,coin_type_b:b}=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,b,y]}),B=O.CoinAssist.fromBalance(A,y,t);t.transferObjects([B],this.sdk.getSenderAddress())})}),t}collectRewardAndFeePayload(e,t){return t=t||new ce.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=q.getBinShift(i,u,s),b=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(b)),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 ce.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[b,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:[b,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(C=>C.bin_id===r),B=d.reduce((C,k)=>(0,O.d)(C).plus(k.amount_a),(0,O.d)(0)).add(A?.amount_a||"0"),S=u.reduce((C,k)=>(0,O.d)(C).plus(k.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 Z("InsufficientLiquidity",new Error("Insufficient liquidity"),{[O.DETAILS_KEYS.METHOD_NAME]:"calculateRemoveLiquidityResult",[O.DETAILS_KEYS.REQUEST_PARAMS]:e});let b=q.processBinsByRate([...p],h.toFixed());if(b.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 C=B?S.amount_a:S.amount_b,k=B?S.amount_b:S.amount_a,R=(0,O.d)((0,O.d)(y).div(C).toFixed(9,D.ROUND_UP));R=R.gt(1)?(0,O.d)(1):R;let T=(0,O.d)(C).mul(R);y=y.minus(T);let I=(0,O.d)(k).mul(R),z=(0,O.d)(S.liquidity).mul(R);A.push({...S,amount_a:B?T.toFixed(0):I.toFixed(0),amount_b:B?I.toFixed(0):T.toFixed(0),liquidity:z.toFixed(0)})}return{bins:A,amount_a:A.reduce((S,C)=>(0,O.d)(S).plus(C.amount_a),(0,O.d)(0)).toFixed(0),amount_b:A.reduce((S,C)=>(0,O.d)(S).plus(C.amount_b),(0,O.d)(0)).toFixed(0)}}return b.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:b}=e;return we.autoFillCoinByStrategy(r,i,p,b,d,f,s,u,h)}else return we.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:b,remove_percent:y}=e,{dlmm_pool:A}=this.sdk.sdkOptions,{bins:B}=i,S=new ce.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:C,global_config_id:k}=(0,O.getPackagerConfigs)(A);if(y){let R=(0,O.asUintN)(BigInt(B[0].bin_id)),T=(0,O.asUintN)(BigInt(B[B.length-1].bin_id)),I=Number((0,O.d)(y).mul(1e4).toFixed(0)),[z,$]=S.moveCall({target:`${A.published_at}::pool::remove_liquidity_by_percent`,arguments:[S.object(t),S.object(r),S.pure.u32(Number(R)),S.pure.u32(Number(T)),S.pure.u16(I),S.object(k),S.object(C),S.object(O.CLOCK_ADDRESS)],typeArguments:[d,f]}),nt=O.CoinAssist.fromBalance(z,d,S),at=O.CoinAssist.fromBalance($,f,S);S.transferObjects([nt,at],this.sdk.getSenderAddress())}else{let R=S.pure.vector("u32",B.map(at=>Number((0,O.asUintN)(BigInt(at.bin_id))))),T=S.pure.vector("u128",B.map(at=>at.liquidity)),[I,z]=S.moveCall({target:`${A.published_at}::pool::remove_liquidity`,arguments:[S.object(t),S.object(r),R,T,S.object(k),S.object(C),S.object(O.CLOCK_ADDRESS)],typeArguments:[d,f]}),$=O.CoinAssist.fromBalance(I,d,S),nt=O.CoinAssist.fromBalance(z,f,S);S.transferObjects([$,nt],this.sdk.getSenderAddress())}return this.validateActiveIdSlippage({pool_id:t,active_id:h,max_price_slippage:u,bin_step:b,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:b,amount_a_in_active_bin:y,amount_b_in_active_bin:A,decimals_a:B,decimals_b:S,use_bin_infos:C,max_price_slippage:k}=e,R,T,I,z=r;if(u==="coin_a")R=q.getBinIdFromPrice(f,p,!1,B,S),T=q.getBinIdFromPrice(h,p,!0,B,S),I=q.getBinIdFromPrice(d,p,!0,B,S);else{R=q.getBinIdFromPrice((0,O.d)(1).div(h).toString(),p,!1,B,S),T=q.getBinIdFromPrice((0,O.d)(1).div(f).toString(),p,!0,B,S),I=q.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:I,bin_step:p,lower_bin_id:R,upper_bin_id:T,amount_a_in_active_bin:y,amount_b_in_active_bin:A,strategy_type:b};z=this.sdk.Position.calculateAddLiquidityInfo(at)}let nt={pool_id:t,active_id:I,bin_infos:z,coin_type_a:i,coin_type_b:s,lower_bin_id:R,upper_bin_id:T,strategy_type:b,use_bin_infos:C,max_price_slippage:k,bin_step:p};return this.addLiquidityPayload(nt)}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:b=!1}=e;t=t||new ce.Transaction;let y="lower_bin_id"in e,A=[];if(y){let B=q.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:C,amount_b:k,bins:R}=B,T=O.CoinAssist.buildCoinWithBalance(BigInt(C),s,t),I=O.CoinAssist.buildCoinWithBalance(BigInt(k),u,t);b?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:T,coin_b_obj_id:I,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:T,coin_b_obj_id:I,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:b,coin_b_obj_id:y,strategy_type:A}=e,{dlmm_pool:B,dlmm_router:S}=this.sdk.sdkOptions,{versioned_id:C,global_config_id:k}=(0,O.getPackagerConfigs)(B),{bins:R,amount_a:T,amount_b:I}=h,z=i,$=R[0].bin_id,nt=R[R.length-1].bin_id,at=(0,O.asUintN)(BigInt($)),Gt=Number((0,O.asUintN)(BigInt(f))),Jt=q.getBinShift(f,r,t),G=ki(A);if(i===void 0){let ot=nt-$+1;ot>1e3&&Z("InvalidBinWidth",new Error("Width is too large"),{[O.DETAILS_KEYS.METHOD_NAME]:"openPosition"}),z=p.moveCall({target:`${S.published_at}::${G}::open_position`,arguments:[typeof s=="string"?p.object(s):s,b,y,p.pure.u64(T),p.pure.u64(I),p.pure.u32(Number(at)),p.pure.u16(Number(ot)),p.pure.u32(Number(Gt)),p.pure.u32(Number(Jt)),p.object(k),p.object(C),p.object(O.CLOCK_ADDRESS)],typeArguments:[u,d]})}else{let ot=R.filter(l=>l.amount_a!=="0"||l.amount_b!=="0");if(ot.length===0)return Z("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(ot[0].bin_id)),o=(0,O.asUintN)(BigInt(ot[ot.length-1].bin_id));p.moveCall({target:`${S.published_at}::${G}::add_liquidity`,arguments:[typeof s=="string"?p.object(s):s,p.object(i),b,y,p.pure.u64(T),p.pure.u64(I),p.pure.u32(Number(v)),p.pure.u32(Number(o)),p.pure.u32(Number(Gt)),p.pure.u32(Number(Jt)),p.object(k),p.object(C),p.object(O.CLOCK_ADDRESS)],typeArguments:[u,d]})}return z?p.transferObjects([z,b,y],this.sdk.getSenderAddress()):p.transferObjects([b,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:b,bin_step:y}=e,{bins:A}=d,{dlmm_pool:B,dlmm_router:S}=this.sdk.sdkOptions,{versioned_id:C,global_config_id:k}=(0,O.getPackagerConfigs)(B),R=f.pure.vector("u64",A.map(nt=>nt.amount_a)),T=f.pure.vector("u64",A.map(nt=>nt.amount_b)),I=f.makeMoveVec({elements:A.map(nt=>f.pure.u32(Number((0,O.asUintN)(BigInt(nt.bin_id))))),type:"u32"}),z=d.bins[0].bin_id,$=d.bins[d.bins.length-1].bin_id;if(t===void 0){$-z+1>1e3&&Z("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,I,R,T,f.object(k),f.object(C),f.object(O.CLOCK_ADDRESS)],typeArguments:[i,s]});u>=z&&u<=$&&this.validateActiveIdSlippage({pool_id:r,active_id:u,max_price_slippage:b,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,I,R,T,f.object(k),f.object(C),f.object(O.CLOCK_ADDRESS)],typeArguments:[i,s]}),u>=z&&u<=$&&this.validateActiveIdSlippage({pool_id:r,active_id:u,max_price_slippage:b,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 ce.Transaction;this.collectRewardAndFeePayload(e,t);let r=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:t,sender:(0,Ar.normalizeSuiAddress)("0x0")});if(r.error!=null)return Z("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=Ii(r);return{feeData:i,rewardData:s}}};var Fi=require("@mysten/sui/transactions"),Kt=require("@cetusprotocol/common-sdk");var Sr=require("@mysten/sui/utils");var $e=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,Kt.getPackagerConfigs)(t),b=new Fi.Transaction;b.moveCall({target:`${t.published_at}::pool::flash_swap`,arguments:[b.object(r),b.pure.bool(u),b.pure.bool(d),b.pure.u64(f),b.object(p),b.object(h),b.object(Kt.CLOCK_ADDRESS)],typeArguments:[i,s]});let y=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:b,sender:(0,Sr.normalizeSuiAddress)("0x0")});if(y.error!=null)return Z("FetchError",new Error(y.error),{[Kt.DETAILS_KEYS.METHOD_NAME]:"fetchSwapQuote",[Kt.DETAILS_KEYS.REQUEST_PARAMS]:e});let A=Ci(y,u);return A==null?Z("FetchError",new Error("No quote info"),{[Kt.DETAILS_KEYS.METHOD_NAME]:"preSwapQuote",[Kt.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:b,out_amount:y,a2b:A}=i,B=new Fi.Transaction,S=d?b:(0,Kt.d)(b).mul(1+f).toFixed(0),C=d?(0,Kt.d)(y).mul(1-f).toFixed(0):y,k=Kt.CoinAssist.buildCoinWithBalance(BigInt(S),A?s:u,B),{versioned_id:R,global_config_id:T}=(0,Kt.getPackagerConfigs)(t);return console.log("\u{1F680} ~ SwapModule ~ option:",{...e,in_amount_limit:S,out_amount_limit:C}),h?B.moveCall({target:`${r.published_at}::swap::${A?"swap_a2b_with_partner":"swap_b2a_with_partner"}`,arguments:[B.object(p),B.object(h),k,B.pure.bool(d),B.pure.u64(BigInt(d?b:y)),B.pure.u64(BigInt(d?C:S)),B.object(T),B.object(R),B.object(Kt.CLOCK_ADDRESS)],typeArguments:[s,u]}):B.moveCall({target:`${r.published_at}::swap::${A?"swap_a2b":"swap_b2a"}`,arguments:[B.object(p),k,B.pure.bool(d),B.pure.u64(BigInt(d?b:y)),B.pure.u64(BigInt(d?C:S)),B.object(T),B.object(R),B.object(Kt.CLOCK_ADDRESS)],typeArguments:[s,u]}),B.transferObjects([k],this.sdk.getSenderAddress()),B}};var Be=require("@mysten/sui/transactions"),X=require("@cetusprotocol/common-sdk");var ze=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,X.getPackagerConfigs)(t);try{let i=await this._sdk.FullClient.getObject({id:r,options:{showContent:!0}}),u=(0,X.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=He(f);e.push(h)})}catch(i){return Z("FetchError",i,{[X.DETAILS_KEYS.METHOD_NAME]:"getPartnerList",[X.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,X.getObjectFields)(f);h.partner_id===t&&(d=h.id.id,this._sdk.updateCache(i,d))}),d||Z("NotFound",new Error("Partner cap not found"),{[X.DETAILS_KEYS.METHOD_NAME]:"getPartnerCapId",[X.DETAILS_KEYS.REQUEST_PARAMS]:{owner:e,partner_id:t}})}catch(i){return Z("FetchError",i,{[X.DETAILS_KEYS.METHOD_NAME]:"getPartnerCapId",[X.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,X.getObjectFields)(u);console.log(d),r.push({coin_type:(0,X.fixCoinType)(d.name,!1),balance:d.value})}),r}catch(t){return Z("FetchError",t,{[X.DETAILS_KEYS.METHOD_NAME]:"getPartnerBalance",[X.DETAILS_KEYS.REQUEST_PARAMS]:e})}}async getPartner(e){try{let t=await this._sdk.FullClient.getObject({id:e,options:{showContent:!0}});return He(t)}catch(t){return Z("FetchError",t,{[X.DETAILS_KEYS.METHOD_NAME]:"getPartner",[X.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,X.getPackagerConfigs)(r);t=t||new Be.Transaction;let f=(0,X.d)(s).mul(1e4);return f.gt(1e4)?Z("InvalidParams",new Error("ref_fee_rate is cannot be greater than 1"),{[X.DETAILS_KEYS.METHOD_NAME]:"updateRefFeeRatePayload",[X.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,X.getPackagerConfigs)(s),d=new Be.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,X.getPackagerConfigs)(r);t=t||new Be.Transaction;let h=s>1e12?Math.floor(s/1e3):s,p=u>1e12?Math.floor(u/1e3):u;return p<=h?Z("InvalidParams",new Error("end_time must be greater than start_time"),{[X.DETAILS_KEYS.METHOD_NAME]:"createPartnerPayload",[X.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(X.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,X.getPackagerConfigs)(t),b=new Be.Transaction,y=(0,X.d)(i).mul(1e4);if(y.gt(1e4))return Z("InvalidParams",new Error("ref_fee_rate is cannot be greater than 1"),{[X.DETAILS_KEYS.METHOD_NAME]:"createPartnerPayload",[X.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?Z("InvalidParams",new Error("end_time must be greater than start_time"),{[X.DETAILS_KEYS.METHOD_NAME]:"createPartnerPayload",[X.DETAILS_KEYS.REQUEST_PARAMS]:e}):(b.moveCall({target:`${t.published_at}::partner::create_partner`,arguments:[b.object(f),b.pure.string(r),b.pure.u64(y.toNumber()),b.pure.u64(A),b.pure.u64(B),b.pure.address(d),b.object(h),b.object(p)],typeArguments:[]}),b)}};var Ge=require("@mysten/sui/transactions"),lt=require("@cetusprotocol/common-sdk"),Ni=gi(Ie()),Ve=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(b=>{let y=(0,lt.getObjectFields)(b),A=lt.MathUtil.u128ToI128(new Ni.default(y.value.fields.value.fields.bits)).toString(),B=y.name,S=new Date(Number(B)*1e3).toLocaleString(),k={emissions_per_second:"0",emissions_per_day:"0",emissions_per:lt.MathUtil.fromX64(new Ni.default(A)).toString(),time:B,visualized_time:S};s.push(k)});let d=s.sort((p,b)=>Number(p.time)-Number(b.time)),f=[];f.push({emissions_per_second:t,emissions_per_day:(0,lt.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 b=d[p];if((0,lt.d)(b.time).lte(r))continue;h=(0,lt.d)(h).add((0,lt.d)(b.emissions_per)).toString();let y=(0,lt.d)(h).mul(3600*24).toString();(0,lt.d)(h).lt(0)?(b.emissions_per_second="0",b.emissions_per_day="0"):(b.emissions_per_second=h,b.emissions_per_day=y),f.push(b)}return f}addRewardPayload(e,t){t=t||new Ge.Transaction;let{dlmm_pool:r}=this._sdk.sdkOptions,{global_config_id:i,versioned_id:s}=(0,lt.getPackagerConfigs)(r),{pool_id:u,reward_coin_type:d,reward_amount:f,start_time_seconds:h,end_time_seconds:p,coin_type_a:b,coin_type_b:y}=e,A=lt.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.u64(f),t.pure.option("u64",h),t.pure.u64(p),t.object(i),t.object(s),t.object(lt.CLOCK_ADDRESS)],typeArguments:[b,y,d]}),t}initRewardPayload(e,t){t=t||new Ge.Transaction;let{dlmm_pool:r}=this._sdk.sdkOptions,{global_config_id:i,versioned_id:s}=(0,lt.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(lt.CLOCK_ADDRESS)],typeArguments:[f,h,p]})}),t}buildRewardAccessPayload(e,t){t=t||new Ge.Transaction;let{dlmm_pool:r}=this._sdk.sdkOptions,{global_config_id:i,versioned_id:s}=(0,lt.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 Br=require("@mysten/sui/transactions"),te=require("@cetusprotocol/common-sdk");var Xe=class{constructor(e){this._sdk=e}get sdk(){return this._sdk}buildRewardWhiteListPayload(e,t){t=t||new Br.Transaction;let{dlmm_pool:r}=this._sdk.sdkOptions,{global_config_id:i,versioned_id:s}=(0,te.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,te.getObjectFields)(u).value.fields};r.push(f)}),r}async getDlmmGlobalConfig(){let{dlmm_pool:e}=this._sdk.sdkOptions,{global_config_id:t}=(0,te.getPackagerConfigs)(e);try{let r=await this._sdk.FullClient.getObject({id:t,options:{showContent:!0}}),i=(0,te.getObjectFields)(r),s=i.reward_config.fields,u=s.reward_white_list?.fields?.contents?.map(f=>(0,te.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.non_manager_initialize_reward_cap),reward_public:s.reward_public}}catch(r){return console.log("fetchGlobalConfig error: ",r),Z("FetchError",r,{[te.DETAILS_KEYS.METHOD_NAME]:"getBinStepConfigs",[te.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,te.getObjectFields)(u);return t.pools_id=d.pools.fields.id.id,t}};var Ee=class n extends Er.SdkWrapper{constructor(e){super(e),this._pool=new Se(this),this._position=new Ke(this),this._swap=new $e(this),this._partner=new ze(this),this._reward=new Ve(this),this._config=new Xe(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({...bi,...e}):n.createCustomSDK({...Di,...e})}static createCustomSDK(e){return new n(e)}};var jn=Ee;0&&(module.exports={BASIS_POINT,BASIS_POINT_MAX,BIN_BOUND,BinUtils,CetusDlmmSDK,DEFAULT_MAX_WEIGHT,DEFAULT_MIN_WEIGHT,FEE_PRECISION,FeeUtils,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