@cetusprotocol/sui-clmm-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/.turbo/turbo-build.log +11100 -0
  2. package/README.md +108 -0
  3. package/dist/index.d.mts +2251 -0
  4. package/dist/index.d.ts +2251 -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/docs/add_liquidity.md +145 -0
  10. package/docs/close_position.md +57 -0
  11. package/docs/collect_fees.md +37 -0
  12. package/docs/create_clmm_pool.md +228 -0
  13. package/docs/error_code.md +69 -0
  14. package/docs/get_clmm_pools.md +92 -0
  15. package/docs/get_positions.md +70 -0
  16. package/docs/get_reward.md +53 -0
  17. package/docs/get_ticks.md +39 -0
  18. package/docs/migrate_to_version_6.0.md +143 -0
  19. package/docs/open_position.md +224 -0
  20. package/docs/partner_swap.md +60 -0
  21. package/docs/pre_swap.md +136 -0
  22. package/docs/remove_liquidity.md +124 -0
  23. package/docs/swap.md +153 -0
  24. package/docs/utils.md +85 -0
  25. package/package.json +37 -0
  26. package/src/config/index.ts +2 -0
  27. package/src/config/mainnet.ts +41 -0
  28. package/src/config/testnet.ts +40 -0
  29. package/src/errors/errors.ts +93 -0
  30. package/src/errors/index.ts +1 -0
  31. package/src/index.ts +10 -0
  32. package/src/math/apr.ts +167 -0
  33. package/src/math/index.ts +1 -0
  34. package/src/modules/configModule.ts +540 -0
  35. package/src/modules/index.ts +5 -0
  36. package/src/modules/poolModule.ts +1066 -0
  37. package/src/modules/positionModule.ts +932 -0
  38. package/src/modules/rewarderModule.ts +430 -0
  39. package/src/modules/swapModule.ts +389 -0
  40. package/src/sdk.ts +131 -0
  41. package/src/types/clmm_type.ts +1002 -0
  42. package/src/types/clmmpool.ts +366 -0
  43. package/src/types/config_type.ts +241 -0
  44. package/src/types/index.ts +8 -0
  45. package/src/types/sui.ts +124 -0
  46. package/src/types/token_type.ts +189 -0
  47. package/src/utils/common.ts +426 -0
  48. package/src/utils/index.ts +3 -0
  49. package/src/utils/positionUtils.ts +434 -0
  50. package/src/utils/swapUtils.ts +499 -0
  51. package/tests/add_liquidity.test.ts +121 -0
  52. package/tests/add_liquidity_fix_token.test.ts +182 -0
  53. package/tests/apr.test.ts +71 -0
  54. package/tests/cetus_config.test.ts +26 -0
  55. package/tests/collect_fees.test.ts +11 -0
  56. package/tests/pool.test.ts +267 -0
  57. package/tests/position.test.ts +145 -0
  58. package/tests/remove_liquidity.test.ts +119 -0
  59. package/tests/rewarder.test.ts +60 -0
  60. package/tests/sdk_config.test.ts +49 -0
  61. package/tests/swap.test.ts +254 -0
  62. package/tests/tsconfig.json +26 -0
  63. package/tsconfig.json +5 -0
  64. package/tsup.config.ts +10 -0
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";var go=Object.create;var Ge=Object.defineProperty;var bo=Object.getOwnPropertyDescriptor;var wo=Object.getOwnPropertyNames;var yo=Object.getPrototypeOf,vo=Object.prototype.hasOwnProperty;var Po=(o,t)=>()=>(t||o((t={exports:{}}).exports,t),t.exports),Co=(o,t)=>{for(var e in t)Ge(o,e,{get:t[e],enumerable:!0})},Pn=(o,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of wo(t))!vo.call(o,n)&&n!==e&&Ge(o,n,{get:()=>t[n],enumerable:!(i=bo(t,n))||i.enumerable});return o};var ce=(o,t,e)=>(e=o!=null?go(yo(o)):{},Pn(t||!o||!o.__esModule?Ge(e,"default",{value:o,enumerable:!0}):e,o)),Mo=o=>Pn(Ge({},"__esModule",{value:!0}),o);var ee=Po((Kn,ji)=>{"use strict";(function(o,t){"use strict";function e(y,s){if(!y)throw new Error(s||"Assertion failed")}function i(y,s){y.super_=s;var l=function(){};l.prototype=s.prototype,y.prototype=new l,y.prototype.constructor=y}function n(y,s,l){if(n.isBN(y))return y;this.negative=0,this.words=null,this.length=0,this.red=null,y!==null&&((s==="le"||s==="be")&&(l=s,s=10),this._init(y||0,s||10,l||"be"))}typeof o=="object"?o.exports=n:t.BN=n,n.BN=n,n.wordSize=26;var r;try{typeof window<"u"&&typeof window.Buffer<"u"?r=window.Buffer:r=require("buffer").Buffer}catch{}n.isBN=function(s){return s instanceof n?!0:s!==null&&typeof s=="object"&&s.constructor.wordSize===n.wordSize&&Array.isArray(s.words)},n.max=function(s,l){return s.cmp(l)>0?s:l},n.min=function(s,l){return s.cmp(l)<0?s:l},n.prototype._init=function(s,l,_){if(typeof s=="number")return this._initNumber(s,l,_);if(typeof s=="object")return this._initArray(s,l,_);l==="hex"&&(l=16),e(l===(l|0)&&l>=2&&l<=36),s=s.toString().replace(/\s+/g,"");var p=0;s[0]==="-"&&(p++,this.negative=1),p<s.length&&(l===16?this._parseHex(s,p,_):(this._parseBase(s,l,p),_==="le"&&this._initArray(this.toArray(),l,_)))},n.prototype._initNumber=function(s,l,_){s<0&&(this.negative=1,s=-s),s<67108864?(this.words=[s&67108863],this.length=1):s<4503599627370496?(this.words=[s&67108863,s/67108864&67108863],this.length=2):(e(s<9007199254740992),this.words=[s&67108863,s/67108864&67108863,1],this.length=3),_==="le"&&this._initArray(this.toArray(),l,_)},n.prototype._initArray=function(s,l,_){if(e(typeof s.length=="number"),s.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(s.length/3),this.words=new Array(this.length);for(var p=0;p<this.length;p++)this.words[p]=0;var g,v,C=0;if(_==="be")for(p=s.length-1,g=0;p>=0;p-=3)v=s[p]|s[p-1]<<8|s[p-2]<<16,this.words[g]|=v<<C&67108863,this.words[g+1]=v>>>26-C&67108863,C+=24,C>=26&&(C-=26,g++);else if(_==="le")for(p=0,g=0;p<s.length;p+=3)v=s[p]|s[p+1]<<8|s[p+2]<<16,this.words[g]|=v<<C&67108863,this.words[g+1]=v>>>26-C&67108863,C+=24,C>=26&&(C-=26,g++);return this._strip()};function a(y,s){var l=y.charCodeAt(s);if(l>=48&&l<=57)return l-48;if(l>=65&&l<=70)return l-55;if(l>=97&&l<=102)return l-87;e(!1,"Invalid character in "+y)}function u(y,s,l){var _=a(y,l);return l-1>=s&&(_|=a(y,l-1)<<4),_}n.prototype._parseHex=function(s,l,_){this.length=Math.ceil((s.length-l)/6),this.words=new Array(this.length);for(var p=0;p<this.length;p++)this.words[p]=0;var g=0,v=0,C;if(_==="be")for(p=s.length-1;p>=l;p-=2)C=u(s,l,p)<<g,this.words[v]|=C&67108863,g>=18?(g-=18,v+=1,this.words[v]|=C>>>26):g+=8;else{var m=s.length-l;for(p=m%2===0?l+1:l;p<s.length;p+=2)C=u(s,l,p)<<g,this.words[v]|=C&67108863,g>=18?(g-=18,v+=1,this.words[v]|=C>>>26):g+=8}this._strip()};function d(y,s,l,_){for(var p=0,g=0,v=Math.min(y.length,l),C=s;C<v;C++){var m=y.charCodeAt(C)-48;p*=_,m>=49?g=m-49+10:m>=17?g=m-17+10:g=m,e(m>=0&&g<_,"Invalid character"),p+=g}return p}n.prototype._parseBase=function(s,l,_){this.words=[0],this.length=1;for(var p=0,g=1;g<=67108863;g*=l)p++;p--,g=g/l|0;for(var v=s.length-_,C=v%p,m=Math.min(v,v-C)+_,c=0,b=_;b<m;b+=p)c=d(s,b,b+p,l),this.imuln(g),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c);if(C!==0){var T=1;for(c=d(s,b,s.length,l),b=0;b<C;b++)T*=l;this.imuln(T),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c)}this._strip()},n.prototype.copy=function(s){s.words=new Array(this.length);for(var l=0;l<this.length;l++)s.words[l]=this.words[l];s.length=this.length,s.negative=this.negative,s.red=this.red};function f(y,s){y.words=s.words,y.length=s.length,y.negative=s.negative,y.red=s.red}if(n.prototype._move=function(s){f(s,this)},n.prototype.clone=function(){var s=new n(null);return this.copy(s),s},n.prototype._expand=function(s){for(;this.length<s;)this.words[this.length++]=0;return this},n.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},n.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{n.prototype[Symbol.for("nodejs.util.inspect.custom")]=h}catch{n.prototype.inspect=h}else n.prototype.inspect=h;function h(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var w=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],P=[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],M=[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];n.prototype.toString=function(s,l){s=s||10,l=l|0||1;var _;if(s===16||s==="hex"){_="";for(var p=0,g=0,v=0;v<this.length;v++){var C=this.words[v],m=((C<<p|g)&16777215).toString(16);g=C>>>24-p&16777215,p+=2,p>=26&&(p-=26,v--),g!==0||v!==this.length-1?_=w[6-m.length]+m+_:_=m+_}for(g!==0&&(_=g.toString(16)+_);_.length%l!==0;)_="0"+_;return this.negative!==0&&(_="-"+_),_}if(s===(s|0)&&s>=2&&s<=36){var c=P[s],b=M[s];_="";var T=this.clone();for(T.negative=0;!T.isZero();){var R=T.modrn(b).toString(s);T=T.idivn(b),T.isZero()?_=R+_:_=w[c-R.length]+R+_}for(this.isZero()&&(_="0"+_);_.length%l!==0;)_="0"+_;return this.negative!==0&&(_="-"+_),_}e(!1,"Base should be between 2 and 36")},n.prototype.toNumber=function(){var s=this.words[0];return this.length===2?s+=this.words[1]*67108864:this.length===3&&this.words[2]===1?s+=4503599627370496+this.words[1]*67108864:this.length>2&&e(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-s:s},n.prototype.toJSON=function(){return this.toString(16,2)},r&&(n.prototype.toBuffer=function(s,l){return this.toArrayLike(r,s,l)}),n.prototype.toArray=function(s,l){return this.toArrayLike(Array,s,l)};var x=function(s,l){return s.allocUnsafe?s.allocUnsafe(l):new s(l)};n.prototype.toArrayLike=function(s,l,_){this._strip();var p=this.byteLength(),g=_||Math.max(1,p);e(p<=g,"byte array longer than desired length"),e(g>0,"Requested array length <= 0");var v=x(s,g),C=l==="le"?"LE":"BE";return this["_toArrayLike"+C](v,p),v},n.prototype._toArrayLikeLE=function(s,l){for(var _=0,p=0,g=0,v=0;g<this.length;g++){var C=this.words[g]<<v|p;s[_++]=C&255,_<s.length&&(s[_++]=C>>8&255),_<s.length&&(s[_++]=C>>16&255),v===6?(_<s.length&&(s[_++]=C>>24&255),p=0,v=0):(p=C>>>24,v+=2)}if(_<s.length)for(s[_++]=p;_<s.length;)s[_++]=0},n.prototype._toArrayLikeBE=function(s,l){for(var _=s.length-1,p=0,g=0,v=0;g<this.length;g++){var C=this.words[g]<<v|p;s[_--]=C&255,_>=0&&(s[_--]=C>>8&255),_>=0&&(s[_--]=C>>16&255),v===6?(_>=0&&(s[_--]=C>>24&255),p=0,v=0):(p=C>>>24,v+=2)}if(_>=0)for(s[_--]=p;_>=0;)s[_--]=0},Math.clz32?n.prototype._countBits=function(s){return 32-Math.clz32(s)}:n.prototype._countBits=function(s){var l=s,_=0;return l>=4096&&(_+=13,l>>>=13),l>=64&&(_+=7,l>>>=7),l>=8&&(_+=4,l>>>=4),l>=2&&(_+=2,l>>>=2),_+l},n.prototype._zeroBits=function(s){if(s===0)return 26;var l=s,_=0;return(l&8191)===0&&(_+=13,l>>>=13),(l&127)===0&&(_+=7,l>>>=7),(l&15)===0&&(_+=4,l>>>=4),(l&3)===0&&(_+=2,l>>>=2),(l&1)===0&&_++,_},n.prototype.bitLength=function(){var s=this.words[this.length-1],l=this._countBits(s);return(this.length-1)*26+l};function S(y){for(var s=new Array(y.bitLength()),l=0;l<s.length;l++){var _=l/26|0,p=l%26;s[l]=y.words[_]>>>p&1}return s}n.prototype.zeroBits=function(){if(this.isZero())return 0;for(var s=0,l=0;l<this.length;l++){var _=this._zeroBits(this.words[l]);if(s+=_,_!==26)break}return s},n.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},n.prototype.toTwos=function(s){return this.negative!==0?this.abs().inotn(s).iaddn(1):this.clone()},n.prototype.fromTwos=function(s){return this.testn(s-1)?this.notn(s).iaddn(1).ineg():this.clone()},n.prototype.isNeg=function(){return this.negative!==0},n.prototype.neg=function(){return this.clone().ineg()},n.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},n.prototype.iuor=function(s){for(;this.length<s.length;)this.words[this.length++]=0;for(var l=0;l<s.length;l++)this.words[l]=this.words[l]|s.words[l];return this._strip()},n.prototype.ior=function(s){return e((this.negative|s.negative)===0),this.iuor(s)},n.prototype.or=function(s){return this.length>s.length?this.clone().ior(s):s.clone().ior(this)},n.prototype.uor=function(s){return this.length>s.length?this.clone().iuor(s):s.clone().iuor(this)},n.prototype.iuand=function(s){var l;this.length>s.length?l=s:l=this;for(var _=0;_<l.length;_++)this.words[_]=this.words[_]&s.words[_];return this.length=l.length,this._strip()},n.prototype.iand=function(s){return e((this.negative|s.negative)===0),this.iuand(s)},n.prototype.and=function(s){return this.length>s.length?this.clone().iand(s):s.clone().iand(this)},n.prototype.uand=function(s){return this.length>s.length?this.clone().iuand(s):s.clone().iuand(this)},n.prototype.iuxor=function(s){var l,_;this.length>s.length?(l=this,_=s):(l=s,_=this);for(var p=0;p<_.length;p++)this.words[p]=l.words[p]^_.words[p];if(this!==l)for(;p<l.length;p++)this.words[p]=l.words[p];return this.length=l.length,this._strip()},n.prototype.ixor=function(s){return e((this.negative|s.negative)===0),this.iuxor(s)},n.prototype.xor=function(s){return this.length>s.length?this.clone().ixor(s):s.clone().ixor(this)},n.prototype.uxor=function(s){return this.length>s.length?this.clone().iuxor(s):s.clone().iuxor(this)},n.prototype.inotn=function(s){e(typeof s=="number"&&s>=0);var l=Math.ceil(s/26)|0,_=s%26;this._expand(l),_>0&&l--;for(var p=0;p<l;p++)this.words[p]=~this.words[p]&67108863;return _>0&&(this.words[p]=~this.words[p]&67108863>>26-_),this._strip()},n.prototype.notn=function(s){return this.clone().inotn(s)},n.prototype.setn=function(s,l){e(typeof s=="number"&&s>=0);var _=s/26|0,p=s%26;return this._expand(_+1),l?this.words[_]=this.words[_]|1<<p:this.words[_]=this.words[_]&~(1<<p),this._strip()},n.prototype.iadd=function(s){var l;if(this.negative!==0&&s.negative===0)return this.negative=0,l=this.isub(s),this.negative^=1,this._normSign();if(this.negative===0&&s.negative!==0)return s.negative=0,l=this.isub(s),s.negative=1,l._normSign();var _,p;this.length>s.length?(_=this,p=s):(_=s,p=this);for(var g=0,v=0;v<p.length;v++)l=(_.words[v]|0)+(p.words[v]|0)+g,this.words[v]=l&67108863,g=l>>>26;for(;g!==0&&v<_.length;v++)l=(_.words[v]|0)+g,this.words[v]=l&67108863,g=l>>>26;if(this.length=_.length,g!==0)this.words[this.length]=g,this.length++;else if(_!==this)for(;v<_.length;v++)this.words[v]=_.words[v];return this},n.prototype.add=function(s){var l;return s.negative!==0&&this.negative===0?(s.negative=0,l=this.sub(s),s.negative^=1,l):s.negative===0&&this.negative!==0?(this.negative=0,l=s.sub(this),this.negative=1,l):this.length>s.length?this.clone().iadd(s):s.clone().iadd(this)},n.prototype.isub=function(s){if(s.negative!==0){s.negative=0;var l=this.iadd(s);return s.negative=1,l._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(s),this.negative=1,this._normSign();var _=this.cmp(s);if(_===0)return this.negative=0,this.length=1,this.words[0]=0,this;var p,g;_>0?(p=this,g=s):(p=s,g=this);for(var v=0,C=0;C<g.length;C++)l=(p.words[C]|0)-(g.words[C]|0)+v,v=l>>26,this.words[C]=l&67108863;for(;v!==0&&C<p.length;C++)l=(p.words[C]|0)+v,v=l>>26,this.words[C]=l&67108863;if(v===0&&C<p.length&&p!==this)for(;C<p.length;C++)this.words[C]=p.words[C];return this.length=Math.max(this.length,C),p!==this&&(this.negative=1),this._strip()},n.prototype.sub=function(s){return this.clone().isub(s)};function z(y,s,l){l.negative=s.negative^y.negative;var _=y.length+s.length|0;l.length=_,_=_-1|0;var p=y.words[0]|0,g=s.words[0]|0,v=p*g,C=v&67108863,m=v/67108864|0;l.words[0]=C;for(var c=1;c<_;c++){for(var b=m>>>26,T=m&67108863,R=Math.min(c,s.length-1),F=Math.max(0,c-y.length+1);F<=R;F++){var U=c-F|0;p=y.words[U]|0,g=s.words[F]|0,v=p*g+T,b+=v/67108864|0,T=v&67108863}l.words[c]=T|0,m=b|0}return m!==0?l.words[c]=m|0:l.length--,l._strip()}var $=function(s,l,_){var p=s.words,g=l.words,v=_.words,C=0,m,c,b,T=p[0]|0,R=T&8191,F=T>>>13,U=p[1]|0,G=U&8191,Q=U>>>13,te=p[2]|0,J=te&8191,it=te>>>13,ye=p[3]|0,ot=ye&8191,rt=ye>>>13,ze=p[4]|0,st=ze&8191,at=ze>>>13,an=p[5]|0,ct=an&8191,lt=an>>>13,cn=p[6]|0,ut=cn&8191,dt=cn>>>13,ln=p[7]|0,ft=ln&8191,_t=ln>>>13,un=p[8]|0,ht=un&8191,pt=un>>>13,dn=p[9]|0,mt=dn&8191,gt=dn>>>13,fn=g[0]|0,bt=fn&8191,wt=fn>>>13,_n=g[1]|0,yt=_n&8191,vt=_n>>>13,hn=g[2]|0,Pt=hn&8191,Ct=hn>>>13,pn=g[3]|0,Mt=pn&8191,kt=pn>>>13,mn=g[4]|0,At=mn&8191,Tt=mn>>>13,gn=g[5]|0,xt=gn&8191,St=gn>>>13,bn=g[6]|0,It=bn&8191,Rt=bn>>>13,wn=g[7]|0,Ot=wn&8191,Ft=wn>>>13,yn=g[8]|0,Bt=yn&8191,Et=yn>>>13,vn=g[9]|0,Nt=vn&8191,jt=vn>>>13;_.negative=s.negative^l.negative,_.length=19,m=Math.imul(R,bt),c=Math.imul(R,wt),c=c+Math.imul(F,bt)|0,b=Math.imul(F,wt);var di=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(di>>>26)|0,di&=67108863,m=Math.imul(G,bt),c=Math.imul(G,wt),c=c+Math.imul(Q,bt)|0,b=Math.imul(Q,wt),m=m+Math.imul(R,yt)|0,c=c+Math.imul(R,vt)|0,c=c+Math.imul(F,yt)|0,b=b+Math.imul(F,vt)|0;var fi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(fi>>>26)|0,fi&=67108863,m=Math.imul(J,bt),c=Math.imul(J,wt),c=c+Math.imul(it,bt)|0,b=Math.imul(it,wt),m=m+Math.imul(G,yt)|0,c=c+Math.imul(G,vt)|0,c=c+Math.imul(Q,yt)|0,b=b+Math.imul(Q,vt)|0,m=m+Math.imul(R,Pt)|0,c=c+Math.imul(R,Ct)|0,c=c+Math.imul(F,Pt)|0,b=b+Math.imul(F,Ct)|0;var _i=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(_i>>>26)|0,_i&=67108863,m=Math.imul(ot,bt),c=Math.imul(ot,wt),c=c+Math.imul(rt,bt)|0,b=Math.imul(rt,wt),m=m+Math.imul(J,yt)|0,c=c+Math.imul(J,vt)|0,c=c+Math.imul(it,yt)|0,b=b+Math.imul(it,vt)|0,m=m+Math.imul(G,Pt)|0,c=c+Math.imul(G,Ct)|0,c=c+Math.imul(Q,Pt)|0,b=b+Math.imul(Q,Ct)|0,m=m+Math.imul(R,Mt)|0,c=c+Math.imul(R,kt)|0,c=c+Math.imul(F,Mt)|0,b=b+Math.imul(F,kt)|0;var hi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(hi>>>26)|0,hi&=67108863,m=Math.imul(st,bt),c=Math.imul(st,wt),c=c+Math.imul(at,bt)|0,b=Math.imul(at,wt),m=m+Math.imul(ot,yt)|0,c=c+Math.imul(ot,vt)|0,c=c+Math.imul(rt,yt)|0,b=b+Math.imul(rt,vt)|0,m=m+Math.imul(J,Pt)|0,c=c+Math.imul(J,Ct)|0,c=c+Math.imul(it,Pt)|0,b=b+Math.imul(it,Ct)|0,m=m+Math.imul(G,Mt)|0,c=c+Math.imul(G,kt)|0,c=c+Math.imul(Q,Mt)|0,b=b+Math.imul(Q,kt)|0,m=m+Math.imul(R,At)|0,c=c+Math.imul(R,Tt)|0,c=c+Math.imul(F,At)|0,b=b+Math.imul(F,Tt)|0;var pi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(pi>>>26)|0,pi&=67108863,m=Math.imul(ct,bt),c=Math.imul(ct,wt),c=c+Math.imul(lt,bt)|0,b=Math.imul(lt,wt),m=m+Math.imul(st,yt)|0,c=c+Math.imul(st,vt)|0,c=c+Math.imul(at,yt)|0,b=b+Math.imul(at,vt)|0,m=m+Math.imul(ot,Pt)|0,c=c+Math.imul(ot,Ct)|0,c=c+Math.imul(rt,Pt)|0,b=b+Math.imul(rt,Ct)|0,m=m+Math.imul(J,Mt)|0,c=c+Math.imul(J,kt)|0,c=c+Math.imul(it,Mt)|0,b=b+Math.imul(it,kt)|0,m=m+Math.imul(G,At)|0,c=c+Math.imul(G,Tt)|0,c=c+Math.imul(Q,At)|0,b=b+Math.imul(Q,Tt)|0,m=m+Math.imul(R,xt)|0,c=c+Math.imul(R,St)|0,c=c+Math.imul(F,xt)|0,b=b+Math.imul(F,St)|0;var mi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(mi>>>26)|0,mi&=67108863,m=Math.imul(ut,bt),c=Math.imul(ut,wt),c=c+Math.imul(dt,bt)|0,b=Math.imul(dt,wt),m=m+Math.imul(ct,yt)|0,c=c+Math.imul(ct,vt)|0,c=c+Math.imul(lt,yt)|0,b=b+Math.imul(lt,vt)|0,m=m+Math.imul(st,Pt)|0,c=c+Math.imul(st,Ct)|0,c=c+Math.imul(at,Pt)|0,b=b+Math.imul(at,Ct)|0,m=m+Math.imul(ot,Mt)|0,c=c+Math.imul(ot,kt)|0,c=c+Math.imul(rt,Mt)|0,b=b+Math.imul(rt,kt)|0,m=m+Math.imul(J,At)|0,c=c+Math.imul(J,Tt)|0,c=c+Math.imul(it,At)|0,b=b+Math.imul(it,Tt)|0,m=m+Math.imul(G,xt)|0,c=c+Math.imul(G,St)|0,c=c+Math.imul(Q,xt)|0,b=b+Math.imul(Q,St)|0,m=m+Math.imul(R,It)|0,c=c+Math.imul(R,Rt)|0,c=c+Math.imul(F,It)|0,b=b+Math.imul(F,Rt)|0;var gi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(gi>>>26)|0,gi&=67108863,m=Math.imul(ft,bt),c=Math.imul(ft,wt),c=c+Math.imul(_t,bt)|0,b=Math.imul(_t,wt),m=m+Math.imul(ut,yt)|0,c=c+Math.imul(ut,vt)|0,c=c+Math.imul(dt,yt)|0,b=b+Math.imul(dt,vt)|0,m=m+Math.imul(ct,Pt)|0,c=c+Math.imul(ct,Ct)|0,c=c+Math.imul(lt,Pt)|0,b=b+Math.imul(lt,Ct)|0,m=m+Math.imul(st,Mt)|0,c=c+Math.imul(st,kt)|0,c=c+Math.imul(at,Mt)|0,b=b+Math.imul(at,kt)|0,m=m+Math.imul(ot,At)|0,c=c+Math.imul(ot,Tt)|0,c=c+Math.imul(rt,At)|0,b=b+Math.imul(rt,Tt)|0,m=m+Math.imul(J,xt)|0,c=c+Math.imul(J,St)|0,c=c+Math.imul(it,xt)|0,b=b+Math.imul(it,St)|0,m=m+Math.imul(G,It)|0,c=c+Math.imul(G,Rt)|0,c=c+Math.imul(Q,It)|0,b=b+Math.imul(Q,Rt)|0,m=m+Math.imul(R,Ot)|0,c=c+Math.imul(R,Ft)|0,c=c+Math.imul(F,Ot)|0,b=b+Math.imul(F,Ft)|0;var bi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(bi>>>26)|0,bi&=67108863,m=Math.imul(ht,bt),c=Math.imul(ht,wt),c=c+Math.imul(pt,bt)|0,b=Math.imul(pt,wt),m=m+Math.imul(ft,yt)|0,c=c+Math.imul(ft,vt)|0,c=c+Math.imul(_t,yt)|0,b=b+Math.imul(_t,vt)|0,m=m+Math.imul(ut,Pt)|0,c=c+Math.imul(ut,Ct)|0,c=c+Math.imul(dt,Pt)|0,b=b+Math.imul(dt,Ct)|0,m=m+Math.imul(ct,Mt)|0,c=c+Math.imul(ct,kt)|0,c=c+Math.imul(lt,Mt)|0,b=b+Math.imul(lt,kt)|0,m=m+Math.imul(st,At)|0,c=c+Math.imul(st,Tt)|0,c=c+Math.imul(at,At)|0,b=b+Math.imul(at,Tt)|0,m=m+Math.imul(ot,xt)|0,c=c+Math.imul(ot,St)|0,c=c+Math.imul(rt,xt)|0,b=b+Math.imul(rt,St)|0,m=m+Math.imul(J,It)|0,c=c+Math.imul(J,Rt)|0,c=c+Math.imul(it,It)|0,b=b+Math.imul(it,Rt)|0,m=m+Math.imul(G,Ot)|0,c=c+Math.imul(G,Ft)|0,c=c+Math.imul(Q,Ot)|0,b=b+Math.imul(Q,Ft)|0,m=m+Math.imul(R,Bt)|0,c=c+Math.imul(R,Et)|0,c=c+Math.imul(F,Bt)|0,b=b+Math.imul(F,Et)|0;var wi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(wi>>>26)|0,wi&=67108863,m=Math.imul(mt,bt),c=Math.imul(mt,wt),c=c+Math.imul(gt,bt)|0,b=Math.imul(gt,wt),m=m+Math.imul(ht,yt)|0,c=c+Math.imul(ht,vt)|0,c=c+Math.imul(pt,yt)|0,b=b+Math.imul(pt,vt)|0,m=m+Math.imul(ft,Pt)|0,c=c+Math.imul(ft,Ct)|0,c=c+Math.imul(_t,Pt)|0,b=b+Math.imul(_t,Ct)|0,m=m+Math.imul(ut,Mt)|0,c=c+Math.imul(ut,kt)|0,c=c+Math.imul(dt,Mt)|0,b=b+Math.imul(dt,kt)|0,m=m+Math.imul(ct,At)|0,c=c+Math.imul(ct,Tt)|0,c=c+Math.imul(lt,At)|0,b=b+Math.imul(lt,Tt)|0,m=m+Math.imul(st,xt)|0,c=c+Math.imul(st,St)|0,c=c+Math.imul(at,xt)|0,b=b+Math.imul(at,St)|0,m=m+Math.imul(ot,It)|0,c=c+Math.imul(ot,Rt)|0,c=c+Math.imul(rt,It)|0,b=b+Math.imul(rt,Rt)|0,m=m+Math.imul(J,Ot)|0,c=c+Math.imul(J,Ft)|0,c=c+Math.imul(it,Ot)|0,b=b+Math.imul(it,Ft)|0,m=m+Math.imul(G,Bt)|0,c=c+Math.imul(G,Et)|0,c=c+Math.imul(Q,Bt)|0,b=b+Math.imul(Q,Et)|0,m=m+Math.imul(R,Nt)|0,c=c+Math.imul(R,jt)|0,c=c+Math.imul(F,Nt)|0,b=b+Math.imul(F,jt)|0;var yi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(yi>>>26)|0,yi&=67108863,m=Math.imul(mt,yt),c=Math.imul(mt,vt),c=c+Math.imul(gt,yt)|0,b=Math.imul(gt,vt),m=m+Math.imul(ht,Pt)|0,c=c+Math.imul(ht,Ct)|0,c=c+Math.imul(pt,Pt)|0,b=b+Math.imul(pt,Ct)|0,m=m+Math.imul(ft,Mt)|0,c=c+Math.imul(ft,kt)|0,c=c+Math.imul(_t,Mt)|0,b=b+Math.imul(_t,kt)|0,m=m+Math.imul(ut,At)|0,c=c+Math.imul(ut,Tt)|0,c=c+Math.imul(dt,At)|0,b=b+Math.imul(dt,Tt)|0,m=m+Math.imul(ct,xt)|0,c=c+Math.imul(ct,St)|0,c=c+Math.imul(lt,xt)|0,b=b+Math.imul(lt,St)|0,m=m+Math.imul(st,It)|0,c=c+Math.imul(st,Rt)|0,c=c+Math.imul(at,It)|0,b=b+Math.imul(at,Rt)|0,m=m+Math.imul(ot,Ot)|0,c=c+Math.imul(ot,Ft)|0,c=c+Math.imul(rt,Ot)|0,b=b+Math.imul(rt,Ft)|0,m=m+Math.imul(J,Bt)|0,c=c+Math.imul(J,Et)|0,c=c+Math.imul(it,Bt)|0,b=b+Math.imul(it,Et)|0,m=m+Math.imul(G,Nt)|0,c=c+Math.imul(G,jt)|0,c=c+Math.imul(Q,Nt)|0,b=b+Math.imul(Q,jt)|0;var vi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(vi>>>26)|0,vi&=67108863,m=Math.imul(mt,Pt),c=Math.imul(mt,Ct),c=c+Math.imul(gt,Pt)|0,b=Math.imul(gt,Ct),m=m+Math.imul(ht,Mt)|0,c=c+Math.imul(ht,kt)|0,c=c+Math.imul(pt,Mt)|0,b=b+Math.imul(pt,kt)|0,m=m+Math.imul(ft,At)|0,c=c+Math.imul(ft,Tt)|0,c=c+Math.imul(_t,At)|0,b=b+Math.imul(_t,Tt)|0,m=m+Math.imul(ut,xt)|0,c=c+Math.imul(ut,St)|0,c=c+Math.imul(dt,xt)|0,b=b+Math.imul(dt,St)|0,m=m+Math.imul(ct,It)|0,c=c+Math.imul(ct,Rt)|0,c=c+Math.imul(lt,It)|0,b=b+Math.imul(lt,Rt)|0,m=m+Math.imul(st,Ot)|0,c=c+Math.imul(st,Ft)|0,c=c+Math.imul(at,Ot)|0,b=b+Math.imul(at,Ft)|0,m=m+Math.imul(ot,Bt)|0,c=c+Math.imul(ot,Et)|0,c=c+Math.imul(rt,Bt)|0,b=b+Math.imul(rt,Et)|0,m=m+Math.imul(J,Nt)|0,c=c+Math.imul(J,jt)|0,c=c+Math.imul(it,Nt)|0,b=b+Math.imul(it,jt)|0;var Pi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Pi>>>26)|0,Pi&=67108863,m=Math.imul(mt,Mt),c=Math.imul(mt,kt),c=c+Math.imul(gt,Mt)|0,b=Math.imul(gt,kt),m=m+Math.imul(ht,At)|0,c=c+Math.imul(ht,Tt)|0,c=c+Math.imul(pt,At)|0,b=b+Math.imul(pt,Tt)|0,m=m+Math.imul(ft,xt)|0,c=c+Math.imul(ft,St)|0,c=c+Math.imul(_t,xt)|0,b=b+Math.imul(_t,St)|0,m=m+Math.imul(ut,It)|0,c=c+Math.imul(ut,Rt)|0,c=c+Math.imul(dt,It)|0,b=b+Math.imul(dt,Rt)|0,m=m+Math.imul(ct,Ot)|0,c=c+Math.imul(ct,Ft)|0,c=c+Math.imul(lt,Ot)|0,b=b+Math.imul(lt,Ft)|0,m=m+Math.imul(st,Bt)|0,c=c+Math.imul(st,Et)|0,c=c+Math.imul(at,Bt)|0,b=b+Math.imul(at,Et)|0,m=m+Math.imul(ot,Nt)|0,c=c+Math.imul(ot,jt)|0,c=c+Math.imul(rt,Nt)|0,b=b+Math.imul(rt,jt)|0;var Ci=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Ci>>>26)|0,Ci&=67108863,m=Math.imul(mt,At),c=Math.imul(mt,Tt),c=c+Math.imul(gt,At)|0,b=Math.imul(gt,Tt),m=m+Math.imul(ht,xt)|0,c=c+Math.imul(ht,St)|0,c=c+Math.imul(pt,xt)|0,b=b+Math.imul(pt,St)|0,m=m+Math.imul(ft,It)|0,c=c+Math.imul(ft,Rt)|0,c=c+Math.imul(_t,It)|0,b=b+Math.imul(_t,Rt)|0,m=m+Math.imul(ut,Ot)|0,c=c+Math.imul(ut,Ft)|0,c=c+Math.imul(dt,Ot)|0,b=b+Math.imul(dt,Ft)|0,m=m+Math.imul(ct,Bt)|0,c=c+Math.imul(ct,Et)|0,c=c+Math.imul(lt,Bt)|0,b=b+Math.imul(lt,Et)|0,m=m+Math.imul(st,Nt)|0,c=c+Math.imul(st,jt)|0,c=c+Math.imul(at,Nt)|0,b=b+Math.imul(at,jt)|0;var Mi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Mi>>>26)|0,Mi&=67108863,m=Math.imul(mt,xt),c=Math.imul(mt,St),c=c+Math.imul(gt,xt)|0,b=Math.imul(gt,St),m=m+Math.imul(ht,It)|0,c=c+Math.imul(ht,Rt)|0,c=c+Math.imul(pt,It)|0,b=b+Math.imul(pt,Rt)|0,m=m+Math.imul(ft,Ot)|0,c=c+Math.imul(ft,Ft)|0,c=c+Math.imul(_t,Ot)|0,b=b+Math.imul(_t,Ft)|0,m=m+Math.imul(ut,Bt)|0,c=c+Math.imul(ut,Et)|0,c=c+Math.imul(dt,Bt)|0,b=b+Math.imul(dt,Et)|0,m=m+Math.imul(ct,Nt)|0,c=c+Math.imul(ct,jt)|0,c=c+Math.imul(lt,Nt)|0,b=b+Math.imul(lt,jt)|0;var ki=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(ki>>>26)|0,ki&=67108863,m=Math.imul(mt,It),c=Math.imul(mt,Rt),c=c+Math.imul(gt,It)|0,b=Math.imul(gt,Rt),m=m+Math.imul(ht,Ot)|0,c=c+Math.imul(ht,Ft)|0,c=c+Math.imul(pt,Ot)|0,b=b+Math.imul(pt,Ft)|0,m=m+Math.imul(ft,Bt)|0,c=c+Math.imul(ft,Et)|0,c=c+Math.imul(_t,Bt)|0,b=b+Math.imul(_t,Et)|0,m=m+Math.imul(ut,Nt)|0,c=c+Math.imul(ut,jt)|0,c=c+Math.imul(dt,Nt)|0,b=b+Math.imul(dt,jt)|0;var Ai=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Ai>>>26)|0,Ai&=67108863,m=Math.imul(mt,Ot),c=Math.imul(mt,Ft),c=c+Math.imul(gt,Ot)|0,b=Math.imul(gt,Ft),m=m+Math.imul(ht,Bt)|0,c=c+Math.imul(ht,Et)|0,c=c+Math.imul(pt,Bt)|0,b=b+Math.imul(pt,Et)|0,m=m+Math.imul(ft,Nt)|0,c=c+Math.imul(ft,jt)|0,c=c+Math.imul(_t,Nt)|0,b=b+Math.imul(_t,jt)|0;var Ti=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(Ti>>>26)|0,Ti&=67108863,m=Math.imul(mt,Bt),c=Math.imul(mt,Et),c=c+Math.imul(gt,Bt)|0,b=Math.imul(gt,Et),m=m+Math.imul(ht,Nt)|0,c=c+Math.imul(ht,jt)|0,c=c+Math.imul(pt,Nt)|0,b=b+Math.imul(pt,jt)|0;var xi=(C+m|0)+((c&8191)<<13)|0;C=(b+(c>>>13)|0)+(xi>>>26)|0,xi&=67108863,m=Math.imul(mt,Nt),c=Math.imul(mt,jt),c=c+Math.imul(gt,Nt)|0,b=Math.imul(gt,jt);var Si=(C+m|0)+((c&8191)<<13)|0;return C=(b+(c>>>13)|0)+(Si>>>26)|0,Si&=67108863,v[0]=di,v[1]=fi,v[2]=_i,v[3]=hi,v[4]=pi,v[5]=mi,v[6]=gi,v[7]=bi,v[8]=wi,v[9]=yi,v[10]=vi,v[11]=Pi,v[12]=Ci,v[13]=Mi,v[14]=ki,v[15]=Ai,v[16]=Ti,v[17]=xi,v[18]=Si,C!==0&&(v[19]=C,_.length++),_};Math.imul||($=z);function V(y,s,l){l.negative=s.negative^y.negative,l.length=y.length+s.length;for(var _=0,p=0,g=0;g<l.length-1;g++){var v=p;p=0;for(var C=_&67108863,m=Math.min(g,s.length-1),c=Math.max(0,g-y.length+1);c<=m;c++){var b=g-c,T=y.words[b]|0,R=s.words[c]|0,F=T*R,U=F&67108863;v=v+(F/67108864|0)|0,U=U+C|0,C=U&67108863,v=v+(U>>>26)|0,p+=v>>>26,v&=67108863}l.words[g]=C,_=v,v=p}return _!==0?l.words[g]=_:l.length--,l._strip()}function D(y,s,l){return V(y,s,l)}n.prototype.mulTo=function(s,l){var _,p=this.length+s.length;return this.length===10&&s.length===10?_=$(this,s,l):p<63?_=z(this,s,l):p<1024?_=V(this,s,l):_=D(this,s,l),_};function W(y,s){this.x=y,this.y=s}W.prototype.makeRBT=function(s){for(var l=new Array(s),_=n.prototype._countBits(s)-1,p=0;p<s;p++)l[p]=this.revBin(p,_,s);return l},W.prototype.revBin=function(s,l,_){if(s===0||s===_-1)return s;for(var p=0,g=0;g<l;g++)p|=(s&1)<<l-g-1,s>>=1;return p},W.prototype.permute=function(s,l,_,p,g,v){for(var C=0;C<v;C++)p[C]=l[s[C]],g[C]=_[s[C]]},W.prototype.transform=function(s,l,_,p,g,v){this.permute(v,s,l,_,p,g);for(var C=1;C<g;C<<=1)for(var m=C<<1,c=Math.cos(2*Math.PI/m),b=Math.sin(2*Math.PI/m),T=0;T<g;T+=m)for(var R=c,F=b,U=0;U<C;U++){var G=_[T+U],Q=p[T+U],te=_[T+U+C],J=p[T+U+C],it=R*te-F*J;J=R*J+F*te,te=it,_[T+U]=G+te,p[T+U]=Q+J,_[T+U+C]=G-te,p[T+U+C]=Q-J,U!==m&&(it=c*R-b*F,F=c*F+b*R,R=it)}},W.prototype.guessLen13b=function(s,l){var _=Math.max(l,s)|1,p=_&1,g=0;for(_=_/2|0;_;_=_>>>1)g++;return 1<<g+1+p},W.prototype.conjugate=function(s,l,_){if(!(_<=1))for(var p=0;p<_/2;p++){var g=s[p];s[p]=s[_-p-1],s[_-p-1]=g,g=l[p],l[p]=-l[_-p-1],l[_-p-1]=-g}},W.prototype.normalize13b=function(s,l){for(var _=0,p=0;p<l/2;p++){var g=Math.round(s[2*p+1]/l)*8192+Math.round(s[2*p]/l)+_;s[p]=g&67108863,g<67108864?_=0:_=g/67108864|0}return s},W.prototype.convert13b=function(s,l,_,p){for(var g=0,v=0;v<l;v++)g=g+(s[v]|0),_[2*v]=g&8191,g=g>>>13,_[2*v+1]=g&8191,g=g>>>13;for(v=2*l;v<p;++v)_[v]=0;e(g===0),e((g&-8192)===0)},W.prototype.stub=function(s){for(var l=new Array(s),_=0;_<s;_++)l[_]=0;return l},W.prototype.mulp=function(s,l,_){var p=2*this.guessLen13b(s.length,l.length),g=this.makeRBT(p),v=this.stub(p),C=new Array(p),m=new Array(p),c=new Array(p),b=new Array(p),T=new Array(p),R=new Array(p),F=_.words;F.length=p,this.convert13b(s.words,s.length,C,p),this.convert13b(l.words,l.length,b,p),this.transform(C,v,m,c,p,g),this.transform(b,v,T,R,p,g);for(var U=0;U<p;U++){var G=m[U]*T[U]-c[U]*R[U];c[U]=m[U]*R[U]+c[U]*T[U],m[U]=G}return this.conjugate(m,c,p),this.transform(m,c,F,v,p,g),this.conjugate(F,v,p),this.normalize13b(F,p),_.negative=s.negative^l.negative,_.length=s.length+l.length,_._strip()},n.prototype.mul=function(s){var l=new n(null);return l.words=new Array(this.length+s.length),this.mulTo(s,l)},n.prototype.mulf=function(s){var l=new n(null);return l.words=new Array(this.length+s.length),D(this,s,l)},n.prototype.imul=function(s){return this.clone().mulTo(s,this)},n.prototype.imuln=function(s){var l=s<0;l&&(s=-s),e(typeof s=="number"),e(s<67108864);for(var _=0,p=0;p<this.length;p++){var g=(this.words[p]|0)*s,v=(g&67108863)+(_&67108863);_>>=26,_+=g/67108864|0,_+=v>>>26,this.words[p]=v&67108863}return _!==0&&(this.words[p]=_,this.length++),this.length=s===0?1:this.length,l?this.ineg():this},n.prototype.muln=function(s){return this.clone().imuln(s)},n.prototype.sqr=function(){return this.mul(this)},n.prototype.isqr=function(){return this.imul(this.clone())},n.prototype.pow=function(s){var l=S(s);if(l.length===0)return new n(1);for(var _=this,p=0;p<l.length&&l[p]===0;p++,_=_.sqr());if(++p<l.length)for(var g=_.sqr();p<l.length;p++,g=g.sqr())l[p]!==0&&(_=_.mul(g));return _},n.prototype.iushln=function(s){e(typeof s=="number"&&s>=0);var l=s%26,_=(s-l)/26,p=67108863>>>26-l<<26-l,g;if(l!==0){var v=0;for(g=0;g<this.length;g++){var C=this.words[g]&p,m=(this.words[g]|0)-C<<l;this.words[g]=m|v,v=C>>>26-l}v&&(this.words[g]=v,this.length++)}if(_!==0){for(g=this.length-1;g>=0;g--)this.words[g+_]=this.words[g];for(g=0;g<_;g++)this.words[g]=0;this.length+=_}return this._strip()},n.prototype.ishln=function(s){return e(this.negative===0),this.iushln(s)},n.prototype.iushrn=function(s,l,_){e(typeof s=="number"&&s>=0);var p;l?p=(l-l%26)/26:p=0;var g=s%26,v=Math.min((s-g)/26,this.length),C=67108863^67108863>>>g<<g,m=_;if(p-=v,p=Math.max(0,p),m){for(var c=0;c<v;c++)m.words[c]=this.words[c];m.length=v}if(v!==0)if(this.length>v)for(this.length-=v,c=0;c<this.length;c++)this.words[c]=this.words[c+v];else this.words[0]=0,this.length=1;var b=0;for(c=this.length-1;c>=0&&(b!==0||c>=p);c--){var T=this.words[c]|0;this.words[c]=b<<26-g|T>>>g,b=T&C}return m&&b!==0&&(m.words[m.length++]=b),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},n.prototype.ishrn=function(s,l,_){return e(this.negative===0),this.iushrn(s,l,_)},n.prototype.shln=function(s){return this.clone().ishln(s)},n.prototype.ushln=function(s){return this.clone().iushln(s)},n.prototype.shrn=function(s){return this.clone().ishrn(s)},n.prototype.ushrn=function(s){return this.clone().iushrn(s)},n.prototype.testn=function(s){e(typeof s=="number"&&s>=0);var l=s%26,_=(s-l)/26,p=1<<l;if(this.length<=_)return!1;var g=this.words[_];return!!(g&p)},n.prototype.imaskn=function(s){e(typeof s=="number"&&s>=0);var l=s%26,_=(s-l)/26;if(e(this.negative===0,"imaskn works only with positive numbers"),this.length<=_)return this;if(l!==0&&_++,this.length=Math.min(_,this.length),l!==0){var p=67108863^67108863>>>l<<l;this.words[this.length-1]&=p}return this._strip()},n.prototype.maskn=function(s){return this.clone().imaskn(s)},n.prototype.iaddn=function(s){return e(typeof s=="number"),e(s<67108864),s<0?this.isubn(-s):this.negative!==0?this.length===1&&(this.words[0]|0)<=s?(this.words[0]=s-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(s),this.negative=1,this):this._iaddn(s)},n.prototype._iaddn=function(s){this.words[0]+=s;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},n.prototype.isubn=function(s){if(e(typeof s=="number"),e(s<67108864),s<0)return this.iaddn(-s);if(this.negative!==0)return this.negative=0,this.iaddn(s),this.negative=1,this;if(this.words[0]-=s,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()},n.prototype.addn=function(s){return this.clone().iaddn(s)},n.prototype.subn=function(s){return this.clone().isubn(s)},n.prototype.iabs=function(){return this.negative=0,this},n.prototype.abs=function(){return this.clone().iabs()},n.prototype._ishlnsubmul=function(s,l,_){var p=s.length+_,g;this._expand(p);var v,C=0;for(g=0;g<s.length;g++){v=(this.words[g+_]|0)+C;var m=(s.words[g]|0)*l;v-=m&67108863,C=(v>>26)-(m/67108864|0),this.words[g+_]=v&67108863}for(;g<this.length-_;g++)v=(this.words[g+_]|0)+C,C=v>>26,this.words[g+_]=v&67108863;if(C===0)return this._strip();for(e(C===-1),C=0,g=0;g<this.length;g++)v=-(this.words[g]|0)+C,C=v>>26,this.words[g]=v&67108863;return this.negative=1,this._strip()},n.prototype._wordDiv=function(s,l){var _=this.length-s.length,p=this.clone(),g=s,v=g.words[g.length-1]|0,C=this._countBits(v);_=26-C,_!==0&&(g=g.ushln(_),p.iushln(_),v=g.words[g.length-1]|0);var m=p.length-g.length,c;if(l!=="mod"){c=new n(null),c.length=m+1,c.words=new Array(c.length);for(var b=0;b<c.length;b++)c.words[b]=0}var T=p.clone()._ishlnsubmul(g,1,m);T.negative===0&&(p=T,c&&(c.words[m]=1));for(var R=m-1;R>=0;R--){var F=(p.words[g.length+R]|0)*67108864+(p.words[g.length+R-1]|0);for(F=Math.min(F/v|0,67108863),p._ishlnsubmul(g,F,R);p.negative!==0;)F--,p.negative=0,p._ishlnsubmul(g,1,R),p.isZero()||(p.negative^=1);c&&(c.words[R]=F)}return c&&c._strip(),p._strip(),l!=="div"&&_!==0&&p.iushrn(_),{div:c||null,mod:p}},n.prototype.divmod=function(s,l,_){if(e(!s.isZero()),this.isZero())return{div:new n(0),mod:new n(0)};var p,g,v;return this.negative!==0&&s.negative===0?(v=this.neg().divmod(s,l),l!=="mod"&&(p=v.div.neg()),l!=="div"&&(g=v.mod.neg(),_&&g.negative!==0&&g.iadd(s)),{div:p,mod:g}):this.negative===0&&s.negative!==0?(v=this.divmod(s.neg(),l),l!=="mod"&&(p=v.div.neg()),{div:p,mod:v.mod}):(this.negative&s.negative)!==0?(v=this.neg().divmod(s.neg(),l),l!=="div"&&(g=v.mod.neg(),_&&g.negative!==0&&g.isub(s)),{div:v.div,mod:g}):s.length>this.length||this.cmp(s)<0?{div:new n(0),mod:this}:s.length===1?l==="div"?{div:this.divn(s.words[0]),mod:null}:l==="mod"?{div:null,mod:new n(this.modrn(s.words[0]))}:{div:this.divn(s.words[0]),mod:new n(this.modrn(s.words[0]))}:this._wordDiv(s,l)},n.prototype.div=function(s){return this.divmod(s,"div",!1).div},n.prototype.mod=function(s){return this.divmod(s,"mod",!1).mod},n.prototype.umod=function(s){return this.divmod(s,"mod",!0).mod},n.prototype.divRound=function(s){var l=this.divmod(s);if(l.mod.isZero())return l.div;var _=l.div.negative!==0?l.mod.isub(s):l.mod,p=s.ushrn(1),g=s.andln(1),v=_.cmp(p);return v<0||g===1&&v===0?l.div:l.div.negative!==0?l.div.isubn(1):l.div.iaddn(1)},n.prototype.modrn=function(s){var l=s<0;l&&(s=-s),e(s<=67108863);for(var _=(1<<26)%s,p=0,g=this.length-1;g>=0;g--)p=(_*p+(this.words[g]|0))%s;return l?-p:p},n.prototype.modn=function(s){return this.modrn(s)},n.prototype.idivn=function(s){var l=s<0;l&&(s=-s),e(s<=67108863);for(var _=0,p=this.length-1;p>=0;p--){var g=(this.words[p]|0)+_*67108864;this.words[p]=g/s|0,_=g%s}return this._strip(),l?this.ineg():this},n.prototype.divn=function(s){return this.clone().idivn(s)},n.prototype.egcd=function(s){e(s.negative===0),e(!s.isZero());var l=this,_=s.clone();l.negative!==0?l=l.umod(s):l=l.clone();for(var p=new n(1),g=new n(0),v=new n(0),C=new n(1),m=0;l.isEven()&&_.isEven();)l.iushrn(1),_.iushrn(1),++m;for(var c=_.clone(),b=l.clone();!l.isZero();){for(var T=0,R=1;(l.words[0]&R)===0&&T<26;++T,R<<=1);if(T>0)for(l.iushrn(T);T-- >0;)(p.isOdd()||g.isOdd())&&(p.iadd(c),g.isub(b)),p.iushrn(1),g.iushrn(1);for(var F=0,U=1;(_.words[0]&U)===0&&F<26;++F,U<<=1);if(F>0)for(_.iushrn(F);F-- >0;)(v.isOdd()||C.isOdd())&&(v.iadd(c),C.isub(b)),v.iushrn(1),C.iushrn(1);l.cmp(_)>=0?(l.isub(_),p.isub(v),g.isub(C)):(_.isub(l),v.isub(p),C.isub(g))}return{a:v,b:C,gcd:_.iushln(m)}},n.prototype._invmp=function(s){e(s.negative===0),e(!s.isZero());var l=this,_=s.clone();l.negative!==0?l=l.umod(s):l=l.clone();for(var p=new n(1),g=new n(0),v=_.clone();l.cmpn(1)>0&&_.cmpn(1)>0;){for(var C=0,m=1;(l.words[0]&m)===0&&C<26;++C,m<<=1);if(C>0)for(l.iushrn(C);C-- >0;)p.isOdd()&&p.iadd(v),p.iushrn(1);for(var c=0,b=1;(_.words[0]&b)===0&&c<26;++c,b<<=1);if(c>0)for(_.iushrn(c);c-- >0;)g.isOdd()&&g.iadd(v),g.iushrn(1);l.cmp(_)>=0?(l.isub(_),p.isub(g)):(_.isub(l),g.isub(p))}var T;return l.cmpn(1)===0?T=p:T=g,T.cmpn(0)<0&&T.iadd(s),T},n.prototype.gcd=function(s){if(this.isZero())return s.abs();if(s.isZero())return this.abs();var l=this.clone(),_=s.clone();l.negative=0,_.negative=0;for(var p=0;l.isEven()&&_.isEven();p++)l.iushrn(1),_.iushrn(1);do{for(;l.isEven();)l.iushrn(1);for(;_.isEven();)_.iushrn(1);var g=l.cmp(_);if(g<0){var v=l;l=_,_=v}else if(g===0||_.cmpn(1)===0)break;l.isub(_)}while(!0);return _.iushln(p)},n.prototype.invm=function(s){return this.egcd(s).a.umod(s)},n.prototype.isEven=function(){return(this.words[0]&1)===0},n.prototype.isOdd=function(){return(this.words[0]&1)===1},n.prototype.andln=function(s){return this.words[0]&s},n.prototype.bincn=function(s){e(typeof s=="number");var l=s%26,_=(s-l)/26,p=1<<l;if(this.length<=_)return this._expand(_+1),this.words[_]|=p,this;for(var g=p,v=_;g!==0&&v<this.length;v++){var C=this.words[v]|0;C+=g,g=C>>>26,C&=67108863,this.words[v]=C}return g!==0&&(this.words[v]=g,this.length++),this},n.prototype.isZero=function(){return this.length===1&&this.words[0]===0},n.prototype.cmpn=function(s){var l=s<0;if(this.negative!==0&&!l)return-1;if(this.negative===0&&l)return 1;this._strip();var _;if(this.length>1)_=1;else{l&&(s=-s),e(s<=67108863,"Number is too big");var p=this.words[0]|0;_=p===s?0:p<s?-1:1}return this.negative!==0?-_|0:_},n.prototype.cmp=function(s){if(this.negative!==0&&s.negative===0)return-1;if(this.negative===0&&s.negative!==0)return 1;var l=this.ucmp(s);return this.negative!==0?-l|0:l},n.prototype.ucmp=function(s){if(this.length>s.length)return 1;if(this.length<s.length)return-1;for(var l=0,_=this.length-1;_>=0;_--){var p=this.words[_]|0,g=s.words[_]|0;if(p!==g){p<g?l=-1:p>g&&(l=1);break}}return l},n.prototype.gtn=function(s){return this.cmpn(s)===1},n.prototype.gt=function(s){return this.cmp(s)===1},n.prototype.gten=function(s){return this.cmpn(s)>=0},n.prototype.gte=function(s){return this.cmp(s)>=0},n.prototype.ltn=function(s){return this.cmpn(s)===-1},n.prototype.lt=function(s){return this.cmp(s)===-1},n.prototype.lten=function(s){return this.cmpn(s)<=0},n.prototype.lte=function(s){return this.cmp(s)<=0},n.prototype.eqn=function(s){return this.cmpn(s)===0},n.prototype.eq=function(s){return this.cmp(s)===0},n.red=function(s){return new Z(s)},n.prototype.toRed=function(s){return e(!this.red,"Already a number in reduction context"),e(this.negative===0,"red works only with positives"),s.convertTo(this)._forceRed(s)},n.prototype.fromRed=function(){return e(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},n.prototype._forceRed=function(s){return this.red=s,this},n.prototype.forceRed=function(s){return e(!this.red,"Already a number in reduction context"),this._forceRed(s)},n.prototype.redAdd=function(s){return e(this.red,"redAdd works only with red numbers"),this.red.add(this,s)},n.prototype.redIAdd=function(s){return e(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,s)},n.prototype.redSub=function(s){return e(this.red,"redSub works only with red numbers"),this.red.sub(this,s)},n.prototype.redISub=function(s){return e(this.red,"redISub works only with red numbers"),this.red.isub(this,s)},n.prototype.redShl=function(s){return e(this.red,"redShl works only with red numbers"),this.red.shl(this,s)},n.prototype.redMul=function(s){return e(this.red,"redMul works only with red numbers"),this.red._verify2(this,s),this.red.mul(this,s)},n.prototype.redIMul=function(s){return e(this.red,"redMul works only with red numbers"),this.red._verify2(this,s),this.red.imul(this,s)},n.prototype.redSqr=function(){return e(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},n.prototype.redISqr=function(){return e(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},n.prototype.redSqrt=function(){return e(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},n.prototype.redInvm=function(){return e(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},n.prototype.redNeg=function(){return e(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},n.prototype.redPow=function(s){return e(this.red&&!s.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,s)};var Ht={k256:null,p224:null,p192:null,p25519:null};function et(y,s){this.name=y,this.p=new n(s,16),this.n=this.p.bitLength(),this.k=new n(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}et.prototype._tmp=function(){var s=new n(null);return s.words=new Array(Math.ceil(this.n/13)),s},et.prototype.ireduce=function(s){var l=s,_;do this.split(l,this.tmp),l=this.imulK(l),l=l.iadd(this.tmp),_=l.bitLength();while(_>this.n);var p=_<this.n?-1:l.ucmp(this.p);return p===0?(l.words[0]=0,l.length=1):p>0?l.isub(this.p):l.strip!==void 0?l.strip():l._strip(),l},et.prototype.split=function(s,l){s.iushrn(this.n,0,l)},et.prototype.imulK=function(s){return s.imul(this.k)};function zt(){et.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}i(zt,et),zt.prototype.split=function(s,l){for(var _=4194303,p=Math.min(s.length,9),g=0;g<p;g++)l.words[g]=s.words[g];if(l.length=p,s.length<=9){s.words[0]=0,s.length=1;return}var v=s.words[9];for(l.words[l.length++]=v&_,g=10;g<s.length;g++){var C=s.words[g]|0;s.words[g-10]=(C&_)<<4|v>>>22,v=C}v>>>=22,s.words[g-10]=v,v===0&&s.length>10?s.length-=10:s.length-=9},zt.prototype.imulK=function(s){s.words[s.length]=0,s.words[s.length+1]=0,s.length+=2;for(var l=0,_=0;_<s.length;_++){var p=s.words[_]|0;l+=p*977,s.words[_]=l&67108863,l=p*64+(l/67108864|0)}return s.words[s.length-1]===0&&(s.length--,s.words[s.length-1]===0&&s.length--),s};function se(){et.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}i(se,et);function Yt(){et.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}i(Yt,et);function ae(){et.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}i(ae,et),ae.prototype.imulK=function(s){for(var l=0,_=0;_<s.length;_++){var p=(s.words[_]|0)*19+l,g=p&67108863;p>>>=26,s.words[_]=g,l=p}return l!==0&&(s.words[s.length++]=l),s},n._prime=function(s){if(Ht[s])return Ht[s];var l;if(s==="k256")l=new zt;else if(s==="p224")l=new se;else if(s==="p192")l=new Yt;else if(s==="p25519")l=new ae;else throw new Error("Unknown prime "+s);return Ht[s]=l,l};function Z(y){if(typeof y=="string"){var s=n._prime(y);this.m=s.p,this.prime=s}else e(y.gtn(1),"modulus must be greater than 1"),this.m=y,this.prime=null}Z.prototype._verify1=function(s){e(s.negative===0,"red works only with positives"),e(s.red,"red works only with red numbers")},Z.prototype._verify2=function(s,l){e((s.negative|l.negative)===0,"red works only with positives"),e(s.red&&s.red===l.red,"red works only with red numbers")},Z.prototype.imod=function(s){return this.prime?this.prime.ireduce(s)._forceRed(this):(f(s,s.umod(this.m)._forceRed(this)),s)},Z.prototype.neg=function(s){return s.isZero()?s.clone():this.m.sub(s)._forceRed(this)},Z.prototype.add=function(s,l){this._verify2(s,l);var _=s.add(l);return _.cmp(this.m)>=0&&_.isub(this.m),_._forceRed(this)},Z.prototype.iadd=function(s,l){this._verify2(s,l);var _=s.iadd(l);return _.cmp(this.m)>=0&&_.isub(this.m),_},Z.prototype.sub=function(s,l){this._verify2(s,l);var _=s.sub(l);return _.cmpn(0)<0&&_.iadd(this.m),_._forceRed(this)},Z.prototype.isub=function(s,l){this._verify2(s,l);var _=s.isub(l);return _.cmpn(0)<0&&_.iadd(this.m),_},Z.prototype.shl=function(s,l){return this._verify1(s),this.imod(s.ushln(l))},Z.prototype.imul=function(s,l){return this._verify2(s,l),this.imod(s.imul(l))},Z.prototype.mul=function(s,l){return this._verify2(s,l),this.imod(s.mul(l))},Z.prototype.isqr=function(s){return this.imul(s,s.clone())},Z.prototype.sqr=function(s){return this.mul(s,s)},Z.prototype.sqrt=function(s){if(s.isZero())return s.clone();var l=this.m.andln(3);if(e(l%2===1),l===3){var _=this.m.add(new n(1)).iushrn(2);return this.pow(s,_)}for(var p=this.m.subn(1),g=0;!p.isZero()&&p.andln(1)===0;)g++,p.iushrn(1);e(!p.isZero());var v=new n(1).toRed(this),C=v.redNeg(),m=this.m.subn(1).iushrn(1),c=this.m.bitLength();for(c=new n(2*c*c).toRed(this);this.pow(c,m).cmp(C)!==0;)c.redIAdd(C);for(var b=this.pow(c,p),T=this.pow(s,p.addn(1).iushrn(1)),R=this.pow(s,p),F=g;R.cmp(v)!==0;){for(var U=R,G=0;U.cmp(v)!==0;G++)U=U.redSqr();e(G<F);var Q=this.pow(b,new n(1).iushln(F-G-1));T=T.redMul(Q),b=Q.redSqr(),R=R.redMul(b),F=G}return T},Z.prototype.invm=function(s){var l=s._invmp(this.m);return l.negative!==0?(l.negative=0,this.imod(l).redNeg()):this.imod(l)},Z.prototype.pow=function(s,l){if(l.isZero())return new n(1).toRed(this);if(l.cmpn(1)===0)return s.clone();var _=4,p=new Array(1<<_);p[0]=new n(1).toRed(this),p[1]=s;for(var g=2;g<p.length;g++)p[g]=this.mul(p[g-1],s);var v=p[0],C=0,m=0,c=l.bitLength()%26;for(c===0&&(c=26),g=l.length-1;g>=0;g--){for(var b=l.words[g],T=c-1;T>=0;T--){var R=b>>T&1;if(v!==p[0]&&(v=this.sqr(v)),R===0&&C===0){m=0;continue}C<<=1,C|=R,m++,!(m!==_&&(g!==0||T!==0))&&(v=this.mul(v,p[C]),m=0,C=0)}c=26}return v},Z.prototype.convertTo=function(s){var l=s.umod(this.m);return l===s?l.clone():l},Z.prototype.convertFrom=function(s){var l=s.clone();return l.red=null,l},n.mont=function(s){return new Kt(s)};function Kt(y){Z.call(this,y),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new n(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)}i(Kt,Z),Kt.prototype.convertTo=function(s){return this.imod(s.ushln(this.shift))},Kt.prototype.convertFrom=function(s){var l=this.imod(s.mul(this.rinv));return l.red=null,l},Kt.prototype.imul=function(s,l){if(s.isZero()||l.isZero())return s.words[0]=0,s.length=1,s;var _=s.imul(l),p=_.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),g=_.isub(p).iushrn(this.shift),v=g;return g.cmp(this.m)>=0?v=g.isub(this.m):g.cmpn(0)<0&&(v=g.iadd(this.m)),v._forceRed(this)},Kt.prototype.mul=function(s,l){if(s.isZero()||l.isZero())return new n(0)._forceRed(this);var _=s.mul(l),p=_.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),g=_.isub(p).iushrn(this.shift),v=g;return g.cmp(this.m)>=0?v=g.isub(this.m):g.cmpn(0)<0&&(v=g.iadd(this.m)),v._forceRed(this)},Kt.prototype.invm=function(s){var l=this.imod(s._invmp(this.m).mul(this.r2));return l._forceRed(this)}})(typeof ji>"u"||ji,Kn)});var Xr={};Co(Xr,{AMM_SWAP_MODULE:()=>$r,CetusClmmSDK:()=>He,ClmmError:()=>he,ClmmExpectSwapModule:()=>Eo,ClmmFetcherModule:()=>Qt,ClmmIntegratePoolModule:()=>Me,ClmmIntegratePoolV2Module:()=>Vt,ClmmIntegratePoolV3Module:()=>Re,ClmmIntegrateRouterModule:()=>Oe,ClmmIntegrateRouterWithPartnerModule:()=>Di,ClmmIntegrateUtilsModule:()=>Li,ClmmPartnerModule:()=>qi,ClmmPositionStatus:()=>$i,ConfigErrorCode:()=>pe,ConfigModule:()=>Ie,DeepbookClobV2Module:()=>jo,DeepbookCustodianV2Module:()=>No,DeepbookEndpointsV2Module:()=>qo,POOL_STRUCT:()=>Ur,PartnerErrorCode:()=>Ei,PoolErrorCode:()=>Ce,PoolModule:()=>Le,PositionErrorCode:()=>Se,PositionModule:()=>Ue,PositionUtils:()=>Zt,RewarderModule:()=>Ke,RouterErrorCode:()=>Un,SwapErrorCode:()=>Bi,SwapModule:()=>We,SwapUtils:()=>Xt,TypesErrorCode:()=>Ni,UtilsErrorCode:()=>Xe,buildClmmPositionName:()=>Lr,buildPool:()=>Ee,buildPoolTransactionInfo:()=>Yi,buildPosition:()=>Ne,buildPositionReward:()=>je,buildPositionTransactionInfo:()=>Xi,buildTickData:()=>qe,buildTickDataByEvent:()=>Ji,buildTransferCoin:()=>tn,buildTransferCoinToSender:()=>De,clmmMainnet:()=>rn,clmmTestnet:()=>sn,computeSwap:()=>Qi,computeSwapStep:()=>so,default:()=>Jr,estPoolAPR:()=>zr,estPositionAPRWithDeltaMethod:()=>Vr,estPositionAPRWithMultiMethod:()=>Qr,findAdjustCoin:()=>ge,getDefaultSuiInputType:()=>Do,getLowerSqrtPriceFromCoinA:()=>Br,getLowerSqrtPriceFromCoinB:()=>Nr,getUpperSqrtPriceFromCoinA:()=>Er,getUpperSqrtPriceFromCoinB:()=>jr,handleError:()=>me,handleMessageError:()=>j,newBits:()=>qr,poolFilterEvenTypes:()=>Ui,transClmmpoolDataWithoutTicks:()=>Vi});module.exports=Mo(Xr);var mo=require("@cetusprotocol/common-sdk");var Ye=require("@mysten/sui/utils"),B=require("@cetusprotocol/common-sdk");var xn="3.7.7",ko=xn,Pe=typeof Buffer=="function",Cn=typeof TextDecoder=="function"?new TextDecoder:void 0,Mn=typeof TextEncoder=="function"?new TextEncoder:void 0,Ao="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",xe=Array.prototype.slice.call(Ao),Ve=(o=>{let t={};return o.forEach((e,i)=>t[e]=i),t})(xe),To=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,Dt=String.fromCharCode.bind(String),kn=typeof Uint8Array.from=="function"?Uint8Array.from.bind(Uint8Array):o=>new Uint8Array(Array.prototype.slice.call(o,0)),Sn=o=>o.replace(/=/g,"").replace(/[+\/]/g,t=>t=="+"?"-":"_"),In=o=>o.replace(/[^A-Za-z0-9\+\/]/g,""),Rn=o=>{let t,e,i,n,r="",a=o.length%3;for(let u=0;u<o.length;){if((e=o.charCodeAt(u++))>255||(i=o.charCodeAt(u++))>255||(n=o.charCodeAt(u++))>255)throw new TypeError("invalid character found");t=e<<16|i<<8|n,r+=xe[t>>18&63]+xe[t>>12&63]+xe[t>>6&63]+xe[t&63]}return a?r.slice(0,a-3)+"===".substring(a):r},Oi=typeof btoa=="function"?o=>btoa(o):Pe?o=>Buffer.from(o,"binary").toString("base64"):Rn,Ii=Pe?o=>Buffer.from(o).toString("base64"):o=>{let e=[];for(let i=0,n=o.length;i<n;i+=4096)e.push(Dt.apply(null,o.subarray(i,i+4096)));return Oi(e.join(""))},Qe=(o,t=!1)=>t?Sn(Ii(o)):Ii(o),xo=o=>{if(o.length<2){var t=o.charCodeAt(0);return t<128?o:t<2048?Dt(192|t>>>6)+Dt(128|t&63):Dt(224|t>>>12&15)+Dt(128|t>>>6&63)+Dt(128|t&63)}else{var t=65536+(o.charCodeAt(0)-55296)*1024+(o.charCodeAt(1)-56320);return Dt(240|t>>>18&7)+Dt(128|t>>>12&63)+Dt(128|t>>>6&63)+Dt(128|t&63)}},So=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,On=o=>o.replace(So,xo),An=Pe?o=>Buffer.from(o,"utf8").toString("base64"):Mn?o=>Ii(Mn.encode(o)):o=>Oi(On(o)),ve=(o,t=!1)=>t?Sn(An(o)):An(o),Tn=o=>ve(o,!0),Io=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,Ro=o=>{switch(o.length){case 4:var t=(7&o.charCodeAt(0))<<18|(63&o.charCodeAt(1))<<12|(63&o.charCodeAt(2))<<6|63&o.charCodeAt(3),e=t-65536;return Dt((e>>>10)+55296)+Dt((e&1023)+56320);case 3:return Dt((15&o.charCodeAt(0))<<12|(63&o.charCodeAt(1))<<6|63&o.charCodeAt(2));default:return Dt((31&o.charCodeAt(0))<<6|63&o.charCodeAt(1))}},Fn=o=>o.replace(Io,Ro),Bn=o=>{if(o=o.replace(/\s+/g,""),!To.test(o))throw new TypeError("malformed base64.");o+="==".slice(2-(o.length&3));let t,e="",i,n;for(let r=0;r<o.length;)t=Ve[o.charAt(r++)]<<18|Ve[o.charAt(r++)]<<12|(i=Ve[o.charAt(r++)])<<6|(n=Ve[o.charAt(r++)]),e+=i===64?Dt(t>>16&255):n===64?Dt(t>>16&255,t>>8&255):Dt(t>>16&255,t>>8&255,t&255);return e},Fi=typeof atob=="function"?o=>atob(In(o)):Pe?o=>Buffer.from(o,"base64").toString("binary"):Bn,En=Pe?o=>kn(Buffer.from(o,"base64")):o=>kn(Fi(o).split("").map(t=>t.charCodeAt(0))),Nn=o=>En(jn(o)),Oo=Pe?o=>Buffer.from(o,"base64").toString("utf8"):Cn?o=>Cn.decode(En(o)):o=>Fn(Fi(o)),jn=o=>In(o.replace(/[-_]/g,t=>t=="-"?"+":"/")),Ri=o=>Oo(jn(o)),Fo=o=>{if(typeof o!="string")return!1;let t=o.replace(/\s+/g,"").replace(/={0,2}$/,"");return!/[^\s0-9a-zA-Z\+/]/.test(t)||!/[^\s0-9a-zA-Z\-_]/.test(t)},qn=o=>({value:o,enumerable:!1,writable:!0,configurable:!0}),Dn=function(){let o=(t,e)=>Object.defineProperty(String.prototype,t,qn(e));o("fromBase64",function(){return Ri(this)}),o("toBase64",function(t){return ve(this,t)}),o("toBase64URI",function(){return ve(this,!0)}),o("toBase64URL",function(){return ve(this,!0)}),o("toUint8Array",function(){return Nn(this)})},Ln=function(){let o=(t,e)=>Object.defineProperty(Uint8Array.prototype,t,qn(e));o("toBase64",function(t){return Qe(this,t)}),o("toBase64URI",function(){return Qe(this,!0)}),o("toBase64URL",function(){return Qe(this,!0)})},Bo=()=>{Dn(),Ln()},Je={version:xn,VERSION:ko,atob:Fi,atobPolyfill:Bn,btoa:Oi,btoaPolyfill:Rn,fromBase64:Ri,toBase64:ve,encode:ve,encodeURI:Tn,encodeURL:Tn,utob:On,btou:Fn,decode:Ri,isValid:Fo,fromUint8Array:Qe,toUint8Array:Nn,extendString:Dn,extendUint8Array:Ln,extendBuiltins:Bo};var $n=require("@cetusprotocol/common-sdk"),Bi=(f=>(f.InvalidSqrtPriceLimitDirection="InvalidSqrtPriceLimitDirection",f.ZeroTradableAmount="ZeroTradableAmount",f.AmountOutBelowMinimum="AmountOutBelowMinimum",f.AmountInAboveMaximum="AmountInAboveMaximum",f.NextTickNotFound="NextTickNotFound",f.TickArraySequenceInvalid="TickArraySequenceInvalid",f.TickArrayCrossingAboveMax="TickArrayCrossingAboveMax",f.TickArrayIndexNotInitialized="TickArrayIndexNotInitialized",f.ParamsLengthNotEqual="ParamsLengthNotEqual",f))(Bi||{}),Se=(n=>(n.InvalidTickEvent="InvalidTickEvent",n.InvalidPositionObject="InvalidPositionObject",n.InvalidPositionRewardObject="InvalidPositionRewardObject",n.InvalidParams="InvalidParams",n))(Se||{}),Ce=(f=>(f.InvalidCoinTypeSequence="InvalidCoinTypeSequence",f.InvalidTickIndex="InvalidTickIndex",f.InvalidPoolObject="InvalidPoolObject",f.InvalidTickObjectId="InvalidTickObjectId",f.InvalidTickObject="InvalidTickObject",f.InvalidTickFields="InvalidTickFields",f.PoolsNotFound="PoolsNotFound",f.StatsPoolsUrlNotSet="StatsPoolsUrlNotSet",f.FetchError="FetchError",f))(Ce||{}),Ei=(e=>(e.NotFoundPartnerObject="NotFoundPartnerObject",e.InvalidPartnerRefFeeFields="InvalidPartnerRefFeeFields",e))(Ei||{}),pe=(i=>(i.InvalidConfig="InvalidConfig",i.InvalidConfigHandle="InvalidConfigHandle",i.InvalidSimulateAccount="InvalidSimulateAccount",i))(pe||{}),Xe=(a=>(a.InvalidSendAddress="InvalidSendAddress",a.InvalidRecipientAddress="InvalidRecipientAddress",a.InvalidRecipientAndAmountLength="InvalidRecipientAndAmountLength",a.InsufficientBalance="InsufficientBalance",a.InvalidTarget="InvalidTarget",a.InvalidTransactionBuilder="InvalidTransactionBuilder",a))(Xe||{}),Un=(a=>(a.InvalidCoin="InvalidCoin",a.NotFoundPath="NotFoundPath",a.NoDowngradeNeedParams="NoDowngradeNeedParams",a.InvalidSwapCountUrl="InvalidSwapCountUrl",a.InvalidTransactionBuilder="InvalidTransactionBuilder",a.InvalidServerResponse="InvalidServerResponse",a))(Un||{}),Ni=(t=>(t.InvalidType="InvalidType",t))(Ni||{}),he=class extends $n.BaseError{constructor(t,e,i){super(t,e||"UnknownError",i)}static isVaultsErrorCode(t,e){return this.isErrorCode(t,e)}},me=(o,t,e)=>{throw new he(t.message,o,e)},j=(o,t,e)=>{throw new he(t,o,e)};var Ie=class{constructor(t){this._cache={};this._sdk=t}get sdk(){return this._sdk}setTokenListCache(t){let{coin_list_handle:e}=(0,B.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),i=`${e}_getCoinConfigs`,n=this.getCache(i),r=n?[...n,...t]:t;this.updateCache(i,r)}async getTokenListByCoinTypes(t){let e={},{coin_list_handle:i}=(0,B.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),n=`${i}_getCoinConfigs`,r=this.getCache(n);if(r!==void 0){let u=r;for(let d of t)for(let f of u)if((0,B.normalizeCoinType)(d)===(0,B.normalizeCoinType)(f.address)){e[d]=f;continue}}let a=t.filter(u=>e[u]===void 0);for(let u of a){let d=`${u}_metadata`,f=this.getCache(d);if(f!==void 0)e[u]=f;else{let h=await this._sdk.FullClient.getCoinMetadata({coinType:u});if(h){let w={id:h.id,pyth_id:"",name:h.name,symbol:h.symbol,official_symbol:h.symbol,coingecko_id:"",decimals:h.decimals,project_url:"",logo_url:h.iconUrl,address:u};e[u]=w,this.updateCache(d,w,B.CACHE_TIME_24H)}else console.log(`not found ${u}`)}}return e}async getCoinConfigs(t=!1,e=!0){let{coin_list_handle:i}=(0,B.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),n=`${i}_getCoinConfigs`,r=this.getCache(n,t);if(r)return r;let u=(await this._sdk.FullClient.getDynamicFieldsByPage(i)).data.map(h=>h.objectId),d=await this._sdk.FullClient.batchGetObjects(u,{showContent:!0}),f=[];return d.forEach(h=>{(h.error!=null||h.data?.content?.dataType!=="moveObject")&&j("FetchError",`when getCoinConfigs get objects error: ${h.error}, please check the rpc and contracts address config.`,{[B.DETAILS_KEYS.METHOD_NAME]:"getCoinConfigs"});let w=this.buildCoinConfig(h,e);this.updateCache(`${i}_${w.address}_getCoinConfig`,w,B.CACHE_TIME_24H),f.push({...w})}),this.updateCache(n,f,B.CACHE_TIME_24H),f}async getCoinConfig(t,e=!1,i=!0){let{coin_list_handle:n}=(0,B.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),r=`${n}_${t}_getCoinConfig`,a=this.getCache(r,e);if(a)return a;let u=await this._sdk.FullClient.getDynamicFieldObject({parentId:n,name:{type:"0x1::type_name::TypeName",value:{name:(0,B.fixCoinType)(t)}}});(u.error!=null||u.data?.content?.dataType!=="moveObject")&&j("FetchError",`when getCoinConfig get object error: ${u.error}, please check the rpc and contracts address config.`,{[B.DETAILS_KEYS.METHOD_NAME]:"getCoinConfig"});let d=this.buildCoinConfig(u,i);return this.updateCache(r,d,B.CACHE_TIME_24H),d}buildCoinConfig(t,e=!0){let i=(0,B.getObjectFields)(t);i=i.value.fields;let n={...i};return n.id=(0,B.getObjectId)(t),n.address=(0,B.extractStructTagFromType)(i.coin_type.fields.name).full_address,i.pyth_id&&(n.pyth_id=(0,Ye.normalizeSuiObjectId)(i.pyth_id)),this.transformExtensions(n,i.extension_fields.fields.contents,e),delete n.coin_type,n}async getClmmPoolConfigs(t=!1,e=!0){let{clmm_pools_handle:i}=(0,B.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),n=`${i}_getClmmPoolConfigs`,r=this.getCache(n,t);if(r)return r;let u=(await this._sdk.FullClient.getDynamicFieldsByPage(i)).data.map(h=>h.objectId),d=await this._sdk.FullClient.batchGetObjects(u,{showContent:!0}),f=[];return d.forEach(h=>{(h.error!=null||h.data?.content?.dataType!=="moveObject")&&j("FetchError",`when getClmmPoolsConfigs get objects error: ${h.error}, please check the rpc and contracts address config.`,{[B.DETAILS_KEYS.METHOD_NAME]:"getClmmPoolConfigs"});let w=this.buildClmmPoolConfig(h,e);this.updateCache(`${w.pool_address}_getClmmPoolConfig`,w,B.CACHE_TIME_24H),f.push({...w})}),this.updateCache(n,f,B.CACHE_TIME_24H),f}async getClmmPoolConfig(t,e=!1,i=!0){let{clmm_pools_handle:n}=(0,B.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),r=`${t}_getClmmPoolConfig`,a=this.getCache(r,e);if(a)return a;let u=await this._sdk.FullClient.getDynamicFieldObject({parentId:n,name:{type:"address",value:t}}),d=this.buildClmmPoolConfig(u,i);return this.updateCache(r,d,B.CACHE_TIME_24H),d}buildClmmPoolConfig(t,e=!0){let i=(0,B.getObjectFields)(t);i=i.value.fields;let n={...i};return n.id=(0,B.getObjectId)(t),n.pool_address=(0,Ye.normalizeSuiObjectId)(i.pool_address),this.transformExtensions(n,i.extension_fields.fields.contents,e),n}async getLaunchpadPoolConfigs(t=!1,e=!0){let{launchpad_pools_handle:i}=(0,B.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),n=`${i}_getLaunchpadPoolConfigs`,r=this.getCache(n,t);if(r)return r;let u=(await this._sdk.FullClient.getDynamicFieldsByPage(i)).data.map(h=>h.objectId),d=await this._sdk.FullClient.batchGetObjects(u,{showContent:!0}),f=[];return d.forEach(h=>{(h.error!=null||h.data?.content?.dataType!=="moveObject")&&j("FetchError",`when getCoinConfigs get objects error: ${h.error}, please check the rpc and contracts address config.`,{[B.DETAILS_KEYS.METHOD_NAME]:"getLaunchpadPoolConfigs"});let w=this.buildLaunchpadPoolConfig(h,e);this.updateCache(`${w.pool_address}_getLaunchpadPoolConfig`,w,B.CACHE_TIME_24H),f.push({...w})}),this.updateCache(n,f,B.CACHE_TIME_24H),f}async getLaunchpadPoolConfig(t,e=!1,i=!0){let{launchpad_pools_handle:n}=(0,B.getPackagerConfigs)(this.sdk.sdkOptions.cetus_config),r=`${t}_getLaunchpadPoolConfig`,a=this.getCache(r,e);if(a)return a;let u=await this._sdk.FullClient.getDynamicFieldObject({parentId:n,name:{type:"address",value:t}}),d=this.buildLaunchpadPoolConfig(u,i);return this.updateCache(r,d,B.CACHE_TIME_24H),d}buildLaunchpadPoolConfig(t,e=!0){let i=(0,B.getObjectFields)(t);i=i.value.fields;let n={...i};n.id=(0,B.getObjectId)(t),n.pool_address=(0,Ye.normalizeSuiObjectId)(i.pool_address),this.transformExtensions(n,i.extension_fields.fields.contents,e);let r=[];i.social_media.fields.contents.forEach(a=>{r.push({name:a.fields.value.fields.name,link:a.fields.value.fields.link})}),n.social_media=r;try{n.regulation=decodeURIComponent(Je.decode(n.regulation).replace(/%/g,"%25"))}catch{n.regulation=Je.decode(n.regulation)}return n}transformExtensions(t,e,i=!0){let n=[];for(let r of e){let{key:a}=r.fields,{value:u}=r.fields;if(a==="labels")try{let d=decodeURIComponent(Je.decode(u));try{u=JSON.parse(d)}catch{u=d}}catch{}i&&(t[a]=u),n.push({key:a,value:u})}delete t.extension_fields,i||(t.extensions=n)}async getCetusConfig(t=!1){let e=this._sdk.sdkOptions.cetus_config.package_id,i=`${e}_getCetusConfig`,n=this.getCache(i,t);if(n!==void 0)return n;let r=await this._sdk.FullClient.getObject({id:e,options:{showPreviousTransaction:!0}}),a=(0,B.getObjectPreviousTransactionDigest)(r),u=await this._sdk.FullClient.queryEventsByPage({Transaction:a}),d={coin_list_id:"",launchpad_pools_id:"",clmm_pools_id:"",admin_cap_id:"",global_config_id:"",coin_list_handle:"",launchpad_pools_handle:"",clmm_pools_handle:""};if(u.data.length>0)for(let f of u.data)switch((0,B.extractStructTagFromType)(f.type).name){case"InitCoinListEvent":d.coin_list_id=f.parsedJson.coin_list_id;break;case"InitLaunchpadPoolsEvent":d.launchpad_pools_id=f.parsedJson.launchpad_pools_id;break;case"InitClmmPoolsEvent":d.clmm_pools_id=f.parsedJson.pools_id;break;case"InitConfigEvent":d.global_config_id=f.parsedJson.global_config_id,d.admin_cap_id=f.parsedJson.admin_cap_id;break;default:break}return d=await this.getCetusConfigHandle(d),d.clmm_pools_id.length>0&&this.updateCache(i,d,B.CACHE_TIME_24H),d}async getCetusConfigHandle(t){let e=[t.clmm_pools_id,t.coin_list_id,t.launchpad_pools_id];return(await this._sdk.FullClient.multiGetObjects({ids:e,options:{showContent:!0}})).forEach(n=>{(n.error!=null||n.data?.content?.dataType!=="moveObject")&&j("InvalidConfigHandle",`when getCetusConfigHandle get objects error: ${n.error}, please check the rpc and contracts address config.`,{[B.DETAILS_KEYS.METHOD_NAME]:"getCetusConfigHandle"});let r=(0,B.getObjectFields)(n),a=(0,B.getObjectType)(n);switch((0,B.extractStructTagFromType)(a).name){case"ClmmPools":t.clmm_pools_handle=r.pools.fields.id.id;break;case"CoinList":t.coin_list_handle=r.coins.fields.id.id;break;case"LaunchpadPools":t.launchpad_pools_handle=r.pools.fields.id.id;break;default:break}}),t}updateCache(t,e,i=B.CACHE_TIME_5MIN){let n=this._cache[t];n?(n.overdue_time=(0,B.getFutureTime)(i),n.value=e):n=new B.CachedContent(e,(0,B.getFutureTime)(i)),this._cache[t]=n}getCache(t,e=!1){try{let i=this._cache[t];if(!i)return;if(e||!i.isValid()){delete this._cache[t];return}return i.value}catch(i){console.error(`Error accessing cache for key ${t}:`,i);return}}};var ao=require("@mysten/sui/client"),Te=require("@mysten/sui/transactions"),be=require("@mysten/sui/utils"),co=ce(ee());var qi="partner",Me="pool_script",Vt="pool_script_v2",Re="pool_script_v3",Oe="router",Di="router_with_partner",Qt="fetcher_script",Eo="expect_swap",Li="utils",No="custodian_v2",jo="clob_v2",qo="endpoints_v2",Do=o=>{if(typeof o=="string"&&o.startsWith("0x"))return"object";if(typeof o=="number"||typeof o=="bigint")return"u64";if(typeof o=="boolean")return"bool";throw new he(`Unknown type for value: ${o}`,"InvalidType")};var Gt=ce(ee()),q=require("@cetusprotocol/common-sdk");var $i=(i=>(i.Deleted="Deleted",i.Exists="Exists",i.NotExists="NotExists",i))($i||{}),Ui=["RemoveLiquidityEvent","SwapEvent","AddLiquidityEvent"];var Ut=ce(ee()),K=require("@cetusprotocol/common-sdk");var ci=require("@mysten/sui/transactions"),ro=ce(ee()),H=require("@cetusprotocol/common-sdk");var Gi=require("@mysten/sui/transactions"),oo=ce(ee()),X=require("@cetusprotocol/common-sdk");var ke=9e15,_e=1e9,Ki="0123456789abcdef",ii="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",ni="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Wi={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-ke,maxE:ke,crypto:!1},zn,le,L=!0,ri="[DecimalError] ",fe=ri+"Invalid argument: ",Gn=ri+"Precision limit exceeded",Vn=ri+"crypto unavailable",Qn="[object Decimal]",$t=Math.floor,qt=Math.pow,Lo=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,$o=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Uo=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Jn=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Jt=1e7,N=7,Ko=9007199254740991,Wo=ii.length-1,Hi=ni.length-1,k={toStringTag:Qn};k.absoluteValue=k.abs=function(){var o=new this.constructor(this);return o.s<0&&(o.s=1),E(o)};k.ceil=function(){return E(new this.constructor(this),this.e+1,2)};k.clampedTo=k.clamp=function(o,t){var e,i=this,n=i.constructor;if(o=new n(o),t=new n(t),!o.s||!t.s)return new n(NaN);if(o.gt(t))throw Error(fe+t);return e=i.cmp(o),e<0?o:i.cmp(t)>0?t:new n(i)};k.comparedTo=k.cmp=function(o){var t,e,i,n,r=this,a=r.d,u=(o=new r.constructor(o)).d,d=r.s,f=o.s;if(!a||!u)return!d||!f?NaN:d!==f?d:a===u?0:!a^d<0?1:-1;if(!a[0]||!u[0])return a[0]?d:u[0]?-f:0;if(d!==f)return d;if(r.e!==o.e)return r.e>o.e^d<0?1:-1;for(i=a.length,n=u.length,t=0,e=i<n?i:n;t<e;++t)if(a[t]!==u[t])return a[t]>u[t]^d<0?1:-1;return i===n?0:i>n^d<0?1:-1};k.cosine=k.cos=function(){var o,t,e=this,i=e.constructor;return e.d?e.d[0]?(o=i.precision,t=i.rounding,i.precision=o+Math.max(e.e,e.sd())+N,i.rounding=1,e=Ho(i,io(i,e)),i.precision=o,i.rounding=t,E(le==2||le==3?e.neg():e,o,t,!0)):new i(1):new i(NaN)};k.cubeRoot=k.cbrt=function(){var o,t,e,i,n,r,a,u,d,f,h=this,w=h.constructor;if(!h.isFinite()||h.isZero())return new w(h);for(L=!1,r=h.s*qt(h.s*h,1/3),!r||Math.abs(r)==1/0?(e=Lt(h.d),o=h.e,(r=(o-e.length+1)%3)&&(e+=r==1||r==-2?"0":"00"),r=qt(e,1/3),o=$t((o+1)/3)-(o%3==(o<0?-1:2)),r==1/0?e="5e"+o:(e=r.toExponential(),e=e.slice(0,e.indexOf("e")+1)+o),i=new w(e),i.s=h.s):i=new w(r.toString()),a=(o=w.precision)+3;;)if(u=i,d=u.times(u).times(u),f=d.plus(h),i=tt(f.plus(h).times(u),f.plus(d),a+2,1),Lt(u.d).slice(0,a)===(e=Lt(i.d)).slice(0,a))if(e=e.slice(a-3,a+1),e=="9999"||!n&&e=="4999"){if(!n&&(E(u,o+1,0),u.times(u).times(u).eq(h))){i=u;break}a+=4,n=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(E(i,o+1,1),t=!i.times(i).times(i).eq(h));break}return L=!0,E(i,o,w.rounding,t)};k.decimalPlaces=k.dp=function(){var o,t=this.d,e=NaN;if(t){if(o=t.length-1,e=(o-$t(this.e/N))*N,o=t[o],o)for(;o%10==0;o/=10)e--;e<0&&(e=0)}return e};k.dividedBy=k.div=function(o){return tt(this,new this.constructor(o))};k.dividedToIntegerBy=k.divToInt=function(o){var t=this,e=t.constructor;return E(tt(t,new e(o),0,1,1),e.precision,e.rounding)};k.equals=k.eq=function(o){return this.cmp(o)===0};k.floor=function(){return E(new this.constructor(this),this.e+1,3)};k.greaterThan=k.gt=function(o){return this.cmp(o)>0};k.greaterThanOrEqualTo=k.gte=function(o){var t=this.cmp(o);return t==1||t===0};k.hyperbolicCosine=k.cosh=function(){var o,t,e,i,n,r=this,a=r.constructor,u=new a(1);if(!r.isFinite())return new a(r.s?1/0:NaN);if(r.isZero())return u;e=a.precision,i=a.rounding,a.precision=e+Math.max(r.e,r.sd())+4,a.rounding=1,n=r.d.length,n<32?(o=Math.ceil(n/3),t=(1/ai(4,o)).toString()):(o=16,t="2.3283064365386962890625e-10"),r=Ae(a,1,r.times(t),new a(1),!0);for(var d,f=o,h=new a(8);f--;)d=r.times(r),r=u.minus(d.times(h.minus(d.times(h))));return E(r,a.precision=e,a.rounding=i,!0)};k.hyperbolicSine=k.sinh=function(){var o,t,e,i,n=this,r=n.constructor;if(!n.isFinite()||n.isZero())return new r(n);if(t=r.precision,e=r.rounding,r.precision=t+Math.max(n.e,n.sd())+4,r.rounding=1,i=n.d.length,i<3)n=Ae(r,2,n,n,!0);else{o=1.4*Math.sqrt(i),o=o>16?16:o|0,n=n.times(1/ai(5,o)),n=Ae(r,2,n,n,!0);for(var a,u=new r(5),d=new r(16),f=new r(20);o--;)a=n.times(n),n=n.times(u.plus(a.times(d.times(a).plus(f))))}return r.precision=t,r.rounding=e,E(n,t,e,!0)};k.hyperbolicTangent=k.tanh=function(){var o,t,e=this,i=e.constructor;return e.isFinite()?e.isZero()?new i(e):(o=i.precision,t=i.rounding,i.precision=o+7,i.rounding=1,tt(e.sinh(),e.cosh(),i.precision=o,i.rounding=t)):new i(e.s)};k.inverseCosine=k.acos=function(){var o=this,t=o.constructor,e=o.abs().cmp(1),i=t.precision,n=t.rounding;return e!==-1?e===0?o.isNeg()?ie(t,i,n):new t(0):new t(NaN):o.isZero()?ie(t,i+4,n).times(.5):(t.precision=i+6,t.rounding=1,o=new t(1).minus(o).div(o.plus(1)).sqrt().atan(),t.precision=i,t.rounding=n,o.times(2))};k.inverseHyperbolicCosine=k.acosh=function(){var o,t,e=this,i=e.constructor;return e.lte(1)?new i(e.eq(1)?0:NaN):e.isFinite()?(o=i.precision,t=i.rounding,i.precision=o+Math.max(Math.abs(e.e),e.sd())+4,i.rounding=1,L=!1,e=e.times(e).minus(1).sqrt().plus(e),L=!0,i.precision=o,i.rounding=t,e.ln()):new i(e)};k.inverseHyperbolicSine=k.asinh=function(){var o,t,e=this,i=e.constructor;return!e.isFinite()||e.isZero()?new i(e):(o=i.precision,t=i.rounding,i.precision=o+2*Math.max(Math.abs(e.e),e.sd())+6,i.rounding=1,L=!1,e=e.times(e).plus(1).sqrt().plus(e),L=!0,i.precision=o,i.rounding=t,e.ln())};k.inverseHyperbolicTangent=k.atanh=function(){var o,t,e,i,n=this,r=n.constructor;return n.isFinite()?n.e>=0?new r(n.abs().eq(1)?n.s/0:n.isZero()?n:NaN):(o=r.precision,t=r.rounding,i=n.sd(),Math.max(i,o)<2*-n.e-1?E(new r(n),o,t,!0):(r.precision=e=i-n.e,n=tt(n.plus(1),new r(1).minus(n),e+o,1),r.precision=o+4,r.rounding=1,n=n.ln(),r.precision=o,r.rounding=t,n.times(.5))):new r(NaN)};k.inverseSine=k.asin=function(){var o,t,e,i,n=this,r=n.constructor;return n.isZero()?new r(n):(t=n.abs().cmp(1),e=r.precision,i=r.rounding,t!==-1?t===0?(o=ie(r,e+4,i).times(.5),o.s=n.s,o):new r(NaN):(r.precision=e+6,r.rounding=1,n=n.div(new r(1).minus(n.times(n)).sqrt().plus(1)).atan(),r.precision=e,r.rounding=i,n.times(2)))};k.inverseTangent=k.atan=function(){var o,t,e,i,n,r,a,u,d,f=this,h=f.constructor,w=h.precision,P=h.rounding;if(f.isFinite()){if(f.isZero())return new h(f);if(f.abs().eq(1)&&w+4<=Hi)return a=ie(h,w+4,P).times(.25),a.s=f.s,a}else{if(!f.s)return new h(NaN);if(w+4<=Hi)return a=ie(h,w+4,P).times(.5),a.s=f.s,a}for(h.precision=u=w+10,h.rounding=1,e=Math.min(28,u/N+2|0),o=e;o;--o)f=f.div(f.times(f).plus(1).sqrt().plus(1));for(L=!1,t=Math.ceil(u/N),i=1,d=f.times(f),a=new h(f),n=f;o!==-1;)if(n=n.times(d),r=a.minus(n.div(i+=2)),n=n.times(d),a=r.plus(n.div(i+=2)),a.d[t]!==void 0)for(o=t;a.d[o]===r.d[o]&&o--;);return e&&(a=a.times(2<<e-1)),L=!0,E(a,h.precision=w,h.rounding=P,!0)};k.isFinite=function(){return!!this.d};k.isInteger=k.isInt=function(){return!!this.d&&$t(this.e/N)>this.d.length-2};k.isNaN=function(){return!this.s};k.isNegative=k.isNeg=function(){return this.s<0};k.isPositive=k.isPos=function(){return this.s>0};k.isZero=function(){return!!this.d&&this.d[0]===0};k.lessThan=k.lt=function(o){return this.cmp(o)<0};k.lessThanOrEqualTo=k.lte=function(o){return this.cmp(o)<1};k.logarithm=k.log=function(o){var t,e,i,n,r,a,u,d,f=this,h=f.constructor,w=h.precision,P=h.rounding,M=5;if(o==null)o=new h(10),t=!0;else{if(o=new h(o),e=o.d,o.s<0||!e||!e[0]||o.eq(1))return new h(NaN);t=o.eq(10)}if(e=f.d,f.s<0||!e||!e[0]||f.eq(1))return new h(e&&!e[0]?-1/0:f.s!=1?NaN:e?0:1/0);if(t)if(e.length>1)r=!0;else{for(n=e[0];n%10===0;)n/=10;r=n!==1}if(L=!1,u=w+M,a=de(f,u),i=t?oi(h,u+10):de(o,u),d=tt(a,i,u,1),Fe(d.d,n=w,P))do if(u+=10,a=de(f,u),i=t?oi(h,u+10):de(o,u),d=tt(a,i,u,1),!r){+Lt(d.d).slice(n+1,n+15)+1==1e14&&(d=E(d,w+1,0));break}while(Fe(d.d,n+=10,P));return L=!0,E(d,w,P)};k.minus=k.sub=function(o){var t,e,i,n,r,a,u,d,f,h,w,P,M=this,x=M.constructor;if(o=new x(o),!M.d||!o.d)return!M.s||!o.s?o=new x(NaN):M.d?o.s=-o.s:o=new x(o.d||M.s!==o.s?M:NaN),o;if(M.s!=o.s)return o.s=-o.s,M.plus(o);if(f=M.d,P=o.d,u=x.precision,d=x.rounding,!f[0]||!P[0]){if(P[0])o.s=-o.s;else if(f[0])o=new x(M);else return new x(d===3?-0:0);return L?E(o,u,d):o}if(e=$t(o.e/N),h=$t(M.e/N),f=f.slice(),r=h-e,r){for(w=r<0,w?(t=f,r=-r,a=P.length):(t=P,e=h,a=f.length),i=Math.max(Math.ceil(u/N),a)+2,r>i&&(r=i,t.length=1),t.reverse(),i=r;i--;)t.push(0);t.reverse()}else{for(i=f.length,a=P.length,w=i<a,w&&(a=i),i=0;i<a;i++)if(f[i]!=P[i]){w=f[i]<P[i];break}r=0}for(w&&(t=f,f=P,P=t,o.s=-o.s),a=f.length,i=P.length-a;i>0;--i)f[a++]=0;for(i=P.length;i>r;){if(f[--i]<P[i]){for(n=i;n&&f[--n]===0;)f[n]=Jt-1;--f[n],f[i]+=Jt}f[i]-=P[i]}for(;f[--a]===0;)f.pop();for(;f[0]===0;f.shift())--e;return f[0]?(o.d=f,o.e=si(f,e),L?E(o,u,d):o):new x(d===3?-0:0)};k.modulo=k.mod=function(o){var t,e=this,i=e.constructor;return o=new i(o),!e.d||!o.s||o.d&&!o.d[0]?new i(NaN):!o.d||e.d&&!e.d[0]?E(new i(e),i.precision,i.rounding):(L=!1,i.modulo==9?(t=tt(e,o.abs(),0,3,1),t.s*=o.s):t=tt(e,o,0,i.modulo,1),t=t.times(o),L=!0,e.minus(t))};k.naturalExponential=k.exp=function(){return Zi(this)};k.naturalLogarithm=k.ln=function(){return de(this)};k.negated=k.neg=function(){var o=new this.constructor(this);return o.s=-o.s,E(o)};k.plus=k.add=function(o){var t,e,i,n,r,a,u,d,f,h,w=this,P=w.constructor;if(o=new P(o),!w.d||!o.d)return!w.s||!o.s?o=new P(NaN):w.d||(o=new P(o.d||w.s===o.s?w:NaN)),o;if(w.s!=o.s)return o.s=-o.s,w.minus(o);if(f=w.d,h=o.d,u=P.precision,d=P.rounding,!f[0]||!h[0])return h[0]||(o=new P(w)),L?E(o,u,d):o;if(r=$t(w.e/N),i=$t(o.e/N),f=f.slice(),n=r-i,n){for(n<0?(e=f,n=-n,a=h.length):(e=h,i=r,a=f.length),r=Math.ceil(u/N),a=r>a?r+1:a+1,n>a&&(n=a,e.length=1),e.reverse();n--;)e.push(0);e.reverse()}for(a=f.length,n=h.length,a-n<0&&(n=a,e=h,h=f,f=e),t=0;n;)t=(f[--n]=f[n]+h[n]+t)/Jt|0,f[n]%=Jt;for(t&&(f.unshift(t),++i),a=f.length;f[--a]==0;)f.pop();return o.d=f,o.e=si(f,i),L?E(o,u,d):o};k.precision=k.sd=function(o){var t,e=this;if(o!==void 0&&o!==!!o&&o!==1&&o!==0)throw Error(fe+o);return e.d?(t=Xn(e.d),o&&e.e+1>t&&(t=e.e+1)):t=NaN,t};k.round=function(){var o=this,t=o.constructor;return E(new t(o),o.e+1,t.rounding)};k.sine=k.sin=function(){var o,t,e=this,i=e.constructor;return e.isFinite()?e.isZero()?new i(e):(o=i.precision,t=i.rounding,i.precision=o+Math.max(e.e,e.sd())+N,i.rounding=1,e=zo(i,io(i,e)),i.precision=o,i.rounding=t,E(le>2?e.neg():e,o,t,!0)):new i(NaN)};k.squareRoot=k.sqrt=function(){var o,t,e,i,n,r,a=this,u=a.d,d=a.e,f=a.s,h=a.constructor;if(f!==1||!u||!u[0])return new h(!f||f<0&&(!u||u[0])?NaN:u?a:1/0);for(L=!1,f=Math.sqrt(+a),f==0||f==1/0?(t=Lt(u),(t.length+d)%2==0&&(t+="0"),f=Math.sqrt(t),d=$t((d+1)/2)-(d<0||d%2),f==1/0?t="5e"+d:(t=f.toExponential(),t=t.slice(0,t.indexOf("e")+1)+d),i=new h(t)):i=new h(f.toString()),e=(d=h.precision)+3;;)if(r=i,i=r.plus(tt(a,r,e+2,1)).times(.5),Lt(r.d).slice(0,e)===(t=Lt(i.d)).slice(0,e))if(t=t.slice(e-3,e+1),t=="9999"||!n&&t=="4999"){if(!n&&(E(r,d+1,0),r.times(r).eq(a))){i=r;break}e+=4,n=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(E(i,d+1,1),o=!i.times(i).eq(a));break}return L=!0,E(i,d,h.rounding,o)};k.tangent=k.tan=function(){var o,t,e=this,i=e.constructor;return e.isFinite()?e.isZero()?new i(e):(o=i.precision,t=i.rounding,i.precision=o+10,i.rounding=1,e=e.sin(),e.s=1,e=tt(e,new i(1).minus(e.times(e)).sqrt(),o+10,0),i.precision=o,i.rounding=t,E(le==2||le==4?e.neg():e,o,t,!0)):new i(NaN)};k.times=k.mul=function(o){var t,e,i,n,r,a,u,d,f,h=this,w=h.constructor,P=h.d,M=(o=new w(o)).d;if(o.s*=h.s,!P||!P[0]||!M||!M[0])return new w(!o.s||P&&!P[0]&&!M||M&&!M[0]&&!P?NaN:!P||!M?o.s/0:o.s*0);for(e=$t(h.e/N)+$t(o.e/N),d=P.length,f=M.length,d<f&&(r=P,P=M,M=r,a=d,d=f,f=a),r=[],a=d+f,i=a;i--;)r.push(0);for(i=f;--i>=0;){for(t=0,n=d+i;n>i;)u=r[n]+M[i]*P[n-i-1]+t,r[n--]=u%Jt|0,t=u/Jt|0;r[n]=(r[n]+t)%Jt|0}for(;!r[--a];)r.pop();return t?++e:r.shift(),o.d=r,o.e=si(r,e),L?E(o,w.precision,w.rounding):o};k.toBinary=function(o,t){return zi(this,2,o,t)};k.toDecimalPlaces=k.toDP=function(o,t){var e=this,i=e.constructor;return e=new i(e),o===void 0?e:(Wt(o,0,_e),t===void 0?t=i.rounding:Wt(t,0,8),E(e,o+e.e+1,t))};k.toExponential=function(o,t){var e,i=this,n=i.constructor;return o===void 0?e=ne(i,!0):(Wt(o,0,_e),t===void 0?t=n.rounding:Wt(t,0,8),i=E(new n(i),o+1,t),e=ne(i,!0,o+1)),i.isNeg()&&!i.isZero()?"-"+e:e};k.toFixed=function(o,t){var e,i,n=this,r=n.constructor;return o===void 0?e=ne(n):(Wt(o,0,_e),t===void 0?t=r.rounding:Wt(t,0,8),i=E(new r(n),o+n.e+1,t),e=ne(i,!1,o+i.e+1)),n.isNeg()&&!n.isZero()?"-"+e:e};k.toFraction=function(o){var t,e,i,n,r,a,u,d,f,h,w,P,M=this,x=M.d,S=M.constructor;if(!x)return new S(M);if(f=e=new S(1),i=d=new S(0),t=new S(i),r=t.e=Xn(x)-M.e-1,a=r%N,t.d[0]=qt(10,a<0?N+a:a),o==null)o=r>0?t:f;else{if(u=new S(o),!u.isInt()||u.lt(f))throw Error(fe+u);o=u.gt(t)?r>0?t:f:u}for(L=!1,u=new S(Lt(x)),h=S.precision,S.precision=r=x.length*N*2;w=tt(u,t,0,1,1),n=e.plus(w.times(i)),n.cmp(o)!=1;)e=i,i=n,n=f,f=d.plus(w.times(n)),d=n,n=t,t=u.minus(w.times(n)),u=n;return n=tt(o.minus(e),i,0,1,1),d=d.plus(n.times(f)),e=e.plus(n.times(i)),d.s=f.s=M.s,P=tt(f,i,r,1).minus(M).abs().cmp(tt(d,e,r,1).minus(M).abs())<1?[f,i]:[d,e],S.precision=h,L=!0,P};k.toHexadecimal=k.toHex=function(o,t){return zi(this,16,o,t)};k.toNearest=function(o,t){var e=this,i=e.constructor;if(e=new i(e),o==null){if(!e.d)return e;o=new i(1),t=i.rounding}else{if(o=new i(o),t===void 0?t=i.rounding:Wt(t,0,8),!e.d)return o.s?e:o;if(!o.d)return o.s&&(o.s=e.s),o}return o.d[0]?(L=!1,e=tt(e,o,0,t,1).times(o),L=!0,E(e)):(o.s=e.s,e=o),e};k.toNumber=function(){return+this};k.toOctal=function(o,t){return zi(this,8,o,t)};k.toPower=k.pow=function(o){var t,e,i,n,r,a,u=this,d=u.constructor,f=+(o=new d(o));if(!u.d||!o.d||!u.d[0]||!o.d[0])return new d(qt(+u,f));if(u=new d(u),u.eq(1))return u;if(i=d.precision,r=d.rounding,o.eq(1))return E(u,i,r);if(t=$t(o.e/N),t>=o.d.length-1&&(e=f<0?-f:f)<=Ko)return n=Yn(d,u,e,i),o.s<0?new d(1).div(n):E(n,i,r);if(a=u.s,a<0){if(t<o.d.length-1)return new d(NaN);if((o.d[t]&1)==0&&(a=1),u.e==0&&u.d[0]==1&&u.d.length==1)return u.s=a,u}return e=qt(+u,f),t=e==0||!isFinite(e)?$t(f*(Math.log("0."+Lt(u.d))/Math.LN10+u.e+1)):new d(e+"").e,t>d.maxE+1||t<d.minE-1?new d(t>0?a/0:0):(L=!1,d.rounding=u.s=1,e=Math.min(12,(t+"").length),n=Zi(o.times(de(u,i+e)),i),n.d&&(n=E(n,i+5,1),Fe(n.d,i,r)&&(t=i+10,n=E(Zi(o.times(de(u,t+e)),t),t+5,1),+Lt(n.d).slice(i+1,i+15)+1==1e14&&(n=E(n,i+1,0)))),n.s=a,L=!0,d.rounding=r,E(n,i,r))};k.toPrecision=function(o,t){var e,i=this,n=i.constructor;return o===void 0?e=ne(i,i.e<=n.toExpNeg||i.e>=n.toExpPos):(Wt(o,1,_e),t===void 0?t=n.rounding:Wt(t,0,8),i=E(new n(i),o,t),e=ne(i,o<=i.e||i.e<=n.toExpNeg,o)),i.isNeg()&&!i.isZero()?"-"+e:e};k.toSignificantDigits=k.toSD=function(o,t){var e=this,i=e.constructor;return o===void 0?(o=i.precision,t=i.rounding):(Wt(o,1,_e),t===void 0?t=i.rounding:Wt(t,0,8)),E(new i(e),o,t)};k.toString=function(){var o=this,t=o.constructor,e=ne(o,o.e<=t.toExpNeg||o.e>=t.toExpPos);return o.isNeg()&&!o.isZero()?"-"+e:e};k.truncated=k.trunc=function(){return E(new this.constructor(this),this.e+1,1)};k.valueOf=k.toJSON=function(){var o=this,t=o.constructor,e=ne(o,o.e<=t.toExpNeg||o.e>=t.toExpPos);return o.isNeg()?"-"+e:e};function Lt(o){var t,e,i,n=o.length-1,r="",a=o[0];if(n>0){for(r+=a,t=1;t<n;t++)i=o[t]+"",e=N-i.length,e&&(r+=ue(e)),r+=i;a=o[t],i=a+"",e=N-i.length,e&&(r+=ue(e))}else if(a===0)return"0";for(;a%10===0;)a/=10;return r+a}function Wt(o,t,e){if(o!==~~o||o<t||o>e)throw Error(fe+o)}function Fe(o,t,e,i){var n,r,a,u;for(r=o[0];r>=10;r/=10)--t;return--t<0?(t+=N,n=0):(n=Math.ceil((t+1)/N),t%=N),r=qt(10,N-t),u=o[n]%r|0,i==null?t<3?(t==0?u=u/100|0:t==1&&(u=u/10|0),a=e<4&&u==99999||e>3&&u==49999||u==5e4||u==0):a=(e<4&&u+1==r||e>3&&u+1==r/2)&&(o[n+1]/r/100|0)==qt(10,t-2)-1||(u==r/2||u==0)&&(o[n+1]/r/100|0)==0:t<4?(t==0?u=u/1e3|0:t==1?u=u/100|0:t==2&&(u=u/10|0),a=(i||e<4)&&u==9999||!i&&e>3&&u==4999):a=((i||e<4)&&u+1==r||!i&&e>3&&u+1==r/2)&&(o[n+1]/r/1e3|0)==qt(10,t-3)-1,a}function ti(o,t,e){for(var i,n=[0],r,a=0,u=o.length;a<u;){for(r=n.length;r--;)n[r]*=t;for(n[0]+=Ki.indexOf(o.charAt(a++)),i=0;i<n.length;i++)n[i]>e-1&&(n[i+1]===void 0&&(n[i+1]=0),n[i+1]+=n[i]/e|0,n[i]%=e)}return n.reverse()}function Ho(o,t){var e,i,n;if(t.isZero())return t;i=t.d.length,i<32?(e=Math.ceil(i/3),n=(1/ai(4,e)).toString()):(e=16,n="2.3283064365386962890625e-10"),o.precision+=e,t=Ae(o,1,t.times(n),new o(1));for(var r=e;r--;){var a=t.times(t);t=a.times(a).minus(a).times(8).plus(1)}return o.precision-=e,t}var tt=function(){function o(i,n,r){var a,u=0,d=i.length;for(i=i.slice();d--;)a=i[d]*n+u,i[d]=a%r|0,u=a/r|0;return u&&i.unshift(u),i}function t(i,n,r,a){var u,d;if(r!=a)d=r>a?1:-1;else for(u=d=0;u<r;u++)if(i[u]!=n[u]){d=i[u]>n[u]?1:-1;break}return d}function e(i,n,r,a){for(var u=0;r--;)i[r]-=u,u=i[r]<n[r]?1:0,i[r]=u*a+i[r]-n[r];for(;!i[0]&&i.length>1;)i.shift()}return function(i,n,r,a,u,d){var f,h,w,P,M,x,S,z,$,V,D,W,Ht,et,zt,se,Yt,ae,Z,Kt,y=i.constructor,s=i.s==n.s?1:-1,l=i.d,_=n.d;if(!l||!l[0]||!_||!_[0])return new y(!i.s||!n.s||(l?_&&l[0]==_[0]:!_)?NaN:l&&l[0]==0||!_?s*0:s/0);for(d?(M=1,h=i.e-n.e):(d=Jt,M=N,h=$t(i.e/M)-$t(n.e/M)),Z=_.length,Yt=l.length,$=new y(s),V=$.d=[],w=0;_[w]==(l[w]||0);w++);if(_[w]>(l[w]||0)&&h--,r==null?(et=r=y.precision,a=y.rounding):u?et=r+(i.e-n.e)+1:et=r,et<0)V.push(1),x=!0;else{if(et=et/M+2|0,w=0,Z==1){for(P=0,_=_[0],et++;(w<Yt||P)&&et--;w++)zt=P*d+(l[w]||0),V[w]=zt/_|0,P=zt%_|0;x=P||w<Yt}else{for(P=d/(_[0]+1)|0,P>1&&(_=o(_,P,d),l=o(l,P,d),Z=_.length,Yt=l.length),se=Z,D=l.slice(0,Z),W=D.length;W<Z;)D[W++]=0;Kt=_.slice(),Kt.unshift(0),ae=_[0],_[1]>=d/2&&++ae;do P=0,f=t(_,D,Z,W),f<0?(Ht=D[0],Z!=W&&(Ht=Ht*d+(D[1]||0)),P=Ht/ae|0,P>1?(P>=d&&(P=d-1),S=o(_,P,d),z=S.length,W=D.length,f=t(S,D,z,W),f==1&&(P--,e(S,Z<z?Kt:_,z,d))):(P==0&&(f=P=1),S=_.slice()),z=S.length,z<W&&S.unshift(0),e(D,S,W,d),f==-1&&(W=D.length,f=t(_,D,Z,W),f<1&&(P++,e(D,Z<W?Kt:_,W,d))),W=D.length):f===0&&(P++,D=[0]),V[w++]=P,f&&D[0]?D[W++]=l[se]||0:(D=[l[se]],W=1);while((se++<Yt||D[0]!==void 0)&&et--);x=D[0]!==void 0}V[0]||V.shift()}if(M==1)$.e=h,zn=x;else{for(w=1,P=V[0];P>=10;P/=10)w++;$.e=w+h*M-1,E($,u?r+$.e+1:r,a,x)}return $}}();function E(o,t,e,i){var n,r,a,u,d,f,h,w,P,M=o.constructor;t:if(t!=null){if(w=o.d,!w)return o;for(n=1,u=w[0];u>=10;u/=10)n++;if(r=t-n,r<0)r+=N,a=t,h=w[P=0],d=h/qt(10,n-a-1)%10|0;else if(P=Math.ceil((r+1)/N),u=w.length,P>=u)if(i){for(;u++<=P;)w.push(0);h=d=0,n=1,r%=N,a=r-N+1}else break t;else{for(h=u=w[P],n=1;u>=10;u/=10)n++;r%=N,a=r-N+n,d=a<0?0:h/qt(10,n-a-1)%10|0}if(i=i||t<0||w[P+1]!==void 0||(a<0?h:h%qt(10,n-a-1)),f=e<4?(d||i)&&(e==0||e==(o.s<0?3:2)):d>5||d==5&&(e==4||i||e==6&&(r>0?a>0?h/qt(10,n-a):0:w[P-1])%10&1||e==(o.s<0?8:7)),t<1||!w[0])return w.length=0,f?(t-=o.e+1,w[0]=qt(10,(N-t%N)%N),o.e=-t||0):w[0]=o.e=0,o;if(r==0?(w.length=P,u=1,P--):(w.length=P+1,u=qt(10,N-r),w[P]=a>0?(h/qt(10,n-a)%qt(10,a)|0)*u:0),f)for(;;)if(P==0){for(r=1,a=w[0];a>=10;a/=10)r++;for(a=w[0]+=u,u=1;a>=10;a/=10)u++;r!=u&&(o.e++,w[0]==Jt&&(w[0]=1));break}else{if(w[P]+=u,w[P]!=Jt)break;w[P--]=0,u=1}for(r=w.length;w[--r]===0;)w.pop()}return L&&(o.e>M.maxE?(o.d=null,o.e=NaN):o.e<M.minE&&(o.e=0,o.d=[0])),o}function ne(o,t,e){if(!o.isFinite())return eo(o);var i,n=o.e,r=Lt(o.d),a=r.length;return t?(e&&(i=e-a)>0?r=r.charAt(0)+"."+r.slice(1)+ue(i):a>1&&(r=r.charAt(0)+"."+r.slice(1)),r=r+(o.e<0?"e":"e+")+o.e):n<0?(r="0."+ue(-n-1)+r,e&&(i=e-a)>0&&(r+=ue(i))):n>=a?(r+=ue(n+1-a),e&&(i=e-n-1)>0&&(r=r+"."+ue(i))):((i=n+1)<a&&(r=r.slice(0,i)+"."+r.slice(i)),e&&(i=e-a)>0&&(n+1===a&&(r+="."),r+=ue(i))),r}function si(o,t){var e=o[0];for(t*=N;e>=10;e/=10)t++;return t}function oi(o,t,e){if(t>Wo)throw L=!0,e&&(o.precision=e),Error(Gn);return E(new o(ii),t,1,!0)}function ie(o,t,e){if(t>Hi)throw Error(Gn);return E(new o(ni),t,e,!0)}function Xn(o){var t=o.length-1,e=t*N+1;if(t=o[t],t){for(;t%10==0;t/=10)e--;for(t=o[0];t>=10;t/=10)e++}return e}function ue(o){for(var t="";o--;)t+="0";return t}function Yn(o,t,e,i){var n,r=new o(1),a=Math.ceil(i/N+4);for(L=!1;;){if(e%2&&(r=r.times(t),Hn(r.d,a)&&(n=!0)),e=$t(e/2),e===0){e=r.d.length-1,n&&r.d[e]===0&&++r.d[e];break}t=t.times(t),Hn(t.d,a)}return L=!0,r}function Wn(o){return o.d[o.d.length-1]&1}function to(o,t,e){for(var i,n,r=new o(t[0]),a=0;++a<t.length;){if(n=new o(t[a]),!n.s){r=n;break}i=r.cmp(n),(i===e||i===0&&r.s===e)&&(r=n)}return r}function Zi(o,t){var e,i,n,r,a,u,d,f=0,h=0,w=0,P=o.constructor,M=P.rounding,x=P.precision;if(!o.d||!o.d[0]||o.e>17)return new P(o.d?o.d[0]?o.s<0?0:1/0:1:o.s?o.s<0?0:o:NaN);for(t==null?(L=!1,d=x):d=t,u=new P(.03125);o.e>-2;)o=o.times(u),w+=5;for(i=Math.log(qt(2,w))/Math.LN10*2+5|0,d+=i,e=r=a=new P(1),P.precision=d;;){if(r=E(r.times(o),d,1),e=e.times(++h),u=a.plus(tt(r,e,d,1)),Lt(u.d).slice(0,d)===Lt(a.d).slice(0,d)){for(n=w;n--;)a=E(a.times(a),d,1);if(t==null)if(f<3&&Fe(a.d,d-i,M,f))P.precision=d+=10,e=r=u=new P(1),h=0,f++;else return E(a,P.precision=x,M,L=!0);else return P.precision=x,a}a=u}}function de(o,t){var e,i,n,r,a,u,d,f,h,w,P,M=1,x=10,S=o,z=S.d,$=S.constructor,V=$.rounding,D=$.precision;if(S.s<0||!z||!z[0]||!S.e&&z[0]==1&&z.length==1)return new $(z&&!z[0]?-1/0:S.s!=1?NaN:z?0:S);if(t==null?(L=!1,h=D):h=t,$.precision=h+=x,e=Lt(z),i=e.charAt(0),Math.abs(r=S.e)<15e14){for(;i<7&&i!=1||i==1&&e.charAt(1)>3;)S=S.times(o),e=Lt(S.d),i=e.charAt(0),M++;r=S.e,i>1?(S=new $("0."+e),r++):S=new $(i+"."+e.slice(1))}else return f=oi($,h+2,D).times(r+""),S=de(new $(i+"."+e.slice(1)),h-x).plus(f),$.precision=D,t==null?E(S,D,V,L=!0):S;for(w=S,d=a=S=tt(S.minus(1),S.plus(1),h,1),P=E(S.times(S),h,1),n=3;;){if(a=E(a.times(P),h,1),f=d.plus(tt(a,new $(n),h,1)),Lt(f.d).slice(0,h)===Lt(d.d).slice(0,h))if(d=d.times(2),r!==0&&(d=d.plus(oi($,h+2,D).times(r+""))),d=tt(d,new $(M),h,1),t==null)if(Fe(d.d,h-x,V,u))$.precision=h+=x,f=a=S=tt(w.minus(1),w.plus(1),h,1),P=E(S.times(S),h,1),n=u=1;else return E(d,$.precision=D,V,L=!0);else return $.precision=D,d;d=f,n+=2}}function eo(o){return String(o.s*o.s/0)}function ei(o,t){var e,i,n;for((e=t.indexOf("."))>-1&&(t=t.replace(".","")),(i=t.search(/e/i))>0?(e<0&&(e=i),e+=+t.slice(i+1),t=t.substring(0,i)):e<0&&(e=t.length),i=0;t.charCodeAt(i)===48;i++);for(n=t.length;t.charCodeAt(n-1)===48;--n);if(t=t.slice(i,n),t){if(n-=i,o.e=e=e-i-1,o.d=[],i=(e+1)%N,e<0&&(i+=N),i<n){for(i&&o.d.push(+t.slice(0,i)),n-=N;i<n;)o.d.push(+t.slice(i,i+=N));t=t.slice(i),i=N-t.length}else i-=n;for(;i--;)t+="0";o.d.push(+t),L&&(o.e>o.constructor.maxE?(o.d=null,o.e=NaN):o.e<o.constructor.minE&&(o.e=0,o.d=[0]))}else o.e=0,o.d=[0];return o}function Zo(o,t){var e,i,n,r,a,u,d,f,h;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Jn.test(t))return ei(o,t)}else if(t==="Infinity"||t==="NaN")return+t||(o.s=NaN),o.e=NaN,o.d=null,o;if($o.test(t))e=16,t=t.toLowerCase();else if(Lo.test(t))e=2;else if(Uo.test(t))e=8;else throw Error(fe+t);for(r=t.search(/p/i),r>0?(d=+t.slice(r+1),t=t.substring(2,r)):t=t.slice(2),r=t.indexOf("."),a=r>=0,i=o.constructor,a&&(t=t.replace(".",""),u=t.length,r=u-r,n=Yn(i,new i(e),r,r*2)),f=ti(t,e,Jt),h=f.length-1,r=h;f[r]===0;--r)f.pop();return r<0?new i(o.s*0):(o.e=si(f,h),o.d=f,L=!1,a&&(o=tt(o,n,u*4)),d&&(o=o.times(Math.abs(d)<54?qt(2,d):Be.pow(2,d))),L=!0,o)}function zo(o,t){var e,i=t.d.length;if(i<3)return t.isZero()?t:Ae(o,2,t,t);e=1.4*Math.sqrt(i),e=e>16?16:e|0,t=t.times(1/ai(5,e)),t=Ae(o,2,t,t);for(var n,r=new o(5),a=new o(16),u=new o(20);e--;)n=t.times(t),t=t.times(r.plus(n.times(a.times(n).minus(u))));return t}function Ae(o,t,e,i,n){var r,a,u,d,f=1,h=o.precision,w=Math.ceil(h/N);for(L=!1,d=e.times(e),u=new o(i);;){if(a=tt(u.times(d),new o(t++*t++),h,1),u=n?i.plus(a):i.minus(a),i=tt(a.times(d),new o(t++*t++),h,1),a=u.plus(i),a.d[w]!==void 0){for(r=w;a.d[r]===u.d[r]&&r--;);if(r==-1)break}r=u,u=i,i=a,a=r,f++}return L=!0,a.d.length=w+1,a}function ai(o,t){for(var e=o;--t;)e*=o;return e}function io(o,t){var e,i=t.s<0,n=ie(o,o.precision,1),r=n.times(.5);if(t=t.abs(),t.lte(r))return le=i?4:1,t;if(e=t.divToInt(n),e.isZero())le=i?3:2;else{if(t=t.minus(e.times(n)),t.lte(r))return le=Wn(e)?i?2:3:i?4:1,t;le=Wn(e)?i?1:4:i?3:2}return t.minus(n).abs()}function zi(o,t,e,i){var n,r,a,u,d,f,h,w,P,M=o.constructor,x=e!==void 0;if(x?(Wt(e,1,_e),i===void 0?i=M.rounding:Wt(i,0,8)):(e=M.precision,i=M.rounding),!o.isFinite())h=eo(o);else{for(h=ne(o),a=h.indexOf("."),x?(n=2,t==16?e=e*4-3:t==8&&(e=e*3-2)):n=t,a>=0&&(h=h.replace(".",""),P=new M(1),P.e=h.length-a,P.d=ti(ne(P),10,n),P.e=P.d.length),w=ti(h,10,n),r=d=w.length;w[--d]==0;)w.pop();if(!w[0])h=x?"0p+0":"0";else{if(a<0?r--:(o=new M(o),o.d=w,o.e=r,o=tt(o,P,e,i,0,n),w=o.d,r=o.e,f=zn),a=w[e],u=n/2,f=f||w[e+1]!==void 0,f=i<4?(a!==void 0||f)&&(i===0||i===(o.s<0?3:2)):a>u||a===u&&(i===4||f||i===6&&w[e-1]&1||i===(o.s<0?8:7)),w.length=e,f)for(;++w[--e]>n-1;)w[e]=0,e||(++r,w.unshift(1));for(d=w.length;!w[d-1];--d);for(a=0,h="";a<d;a++)h+=Ki.charAt(w[a]);if(x){if(d>1)if(t==16||t==8){for(a=t==16?4:3,--d;d%a;d++)h+="0";for(w=ti(h,n,t),d=w.length;!w[d-1];--d);for(a=1,h="1.";a<d;a++)h+=Ki.charAt(w[a])}else h=h.charAt(0)+"."+h.slice(1);h=h+(r<0?"p":"p+")+r}else if(r<0){for(;++r;)h="0"+h;h="0."+h}else if(++r>d)for(r-=d;r--;)h+="0";else r<d&&(h=h.slice(0,r)+"."+h.slice(r))}h=(t==16?"0x":t==2?"0b":t==8?"0o":"")+h}return o.s<0?"-"+h:h}function Hn(o,t){if(o.length>t)return o.length=t,!0}function Go(o){return new this(o).abs()}function Vo(o){return new this(o).acos()}function Qo(o){return new this(o).acosh()}function Jo(o,t){return new this(o).plus(t)}function Xo(o){return new this(o).asin()}function Yo(o){return new this(o).asinh()}function tr(o){return new this(o).atan()}function er(o){return new this(o).atanh()}function ir(o,t){o=new this(o),t=new this(t);var e,i=this.precision,n=this.rounding,r=i+4;return!o.s||!t.s?e=new this(NaN):!o.d&&!t.d?(e=ie(this,r,1).times(t.s>0?.25:.75),e.s=o.s):!t.d||o.isZero()?(e=t.s<0?ie(this,i,n):new this(0),e.s=o.s):!o.d||t.isZero()?(e=ie(this,r,1).times(.5),e.s=o.s):t.s<0?(this.precision=r,this.rounding=1,e=this.atan(tt(o,t,r,1)),t=ie(this,r,1),this.precision=i,this.rounding=n,e=o.s<0?e.minus(t):e.plus(t)):e=this.atan(tt(o,t,r,1)),e}function nr(o){return new this(o).cbrt()}function or(o){return E(o=new this(o),o.e+1,2)}function rr(o,t,e){return new this(o).clamp(t,e)}function sr(o){if(!o||typeof o!="object")throw Error(ri+"Object expected");var t,e,i,n=o.defaults===!0,r=["precision",1,_e,"rounding",0,8,"toExpNeg",-ke,0,"toExpPos",0,ke,"maxE",0,ke,"minE",-ke,0,"modulo",0,9];for(t=0;t<r.length;t+=3)if(e=r[t],n&&(this[e]=Wi[e]),(i=o[e])!==void 0)if($t(i)===i&&i>=r[t+1]&&i<=r[t+2])this[e]=i;else throw Error(fe+e+": "+i);if(e="crypto",n&&(this[e]=Wi[e]),(i=o[e])!==void 0)if(i===!0||i===!1||i===0||i===1)if(i)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[e]=!0;else throw Error(Vn);else this[e]=!1;else throw Error(fe+e+": "+i);return this}function ar(o){return new this(o).cos()}function cr(o){return new this(o).cosh()}function no(o){var t,e,i;function n(r){var a,u,d,f=this;if(!(f instanceof n))return new n(r);if(f.constructor=n,Zn(r)){f.s=r.s,L?!r.d||r.e>n.maxE?(f.e=NaN,f.d=null):r.e<n.minE?(f.e=0,f.d=[0]):(f.e=r.e,f.d=r.d.slice()):(f.e=r.e,f.d=r.d?r.d.slice():r.d);return}if(d=typeof r,d==="number"){if(r===0){f.s=1/r<0?-1:1,f.e=0,f.d=[0];return}if(r<0?(r=-r,f.s=-1):f.s=1,r===~~r&&r<1e7){for(a=0,u=r;u>=10;u/=10)a++;L?a>n.maxE?(f.e=NaN,f.d=null):a<n.minE?(f.e=0,f.d=[0]):(f.e=a,f.d=[r]):(f.e=a,f.d=[r]);return}if(r*0!==0){r||(f.s=NaN),f.e=NaN,f.d=null;return}return ei(f,r.toString())}if(d==="string")return(u=r.charCodeAt(0))===45?(r=r.slice(1),f.s=-1):(u===43&&(r=r.slice(1)),f.s=1),Jn.test(r)?ei(f,r):Zo(f,r);if(d==="bigint")return r<0?(r=-r,f.s=-1):f.s=1,ei(f,r.toString());throw Error(fe+r)}if(n.prototype=k,n.ROUND_UP=0,n.ROUND_DOWN=1,n.ROUND_CEIL=2,n.ROUND_FLOOR=3,n.ROUND_HALF_UP=4,n.ROUND_HALF_DOWN=5,n.ROUND_HALF_EVEN=6,n.ROUND_HALF_CEIL=7,n.ROUND_HALF_FLOOR=8,n.EUCLID=9,n.config=n.set=sr,n.clone=no,n.isDecimal=Zn,n.abs=Go,n.acos=Vo,n.acosh=Qo,n.add=Jo,n.asin=Xo,n.asinh=Yo,n.atan=tr,n.atanh=er,n.atan2=ir,n.cbrt=nr,n.ceil=or,n.clamp=rr,n.cos=ar,n.cosh=cr,n.div=lr,n.exp=ur,n.floor=dr,n.hypot=fr,n.ln=_r,n.log=hr,n.log10=mr,n.log2=pr,n.max=gr,n.min=br,n.mod=wr,n.mul=yr,n.pow=vr,n.random=Pr,n.round=Cr,n.sign=Mr,n.sin=kr,n.sinh=Ar,n.sqrt=Tr,n.sub=xr,n.sum=Sr,n.tan=Ir,n.tanh=Rr,n.trunc=Or,o===void 0&&(o={}),o&&o.defaults!==!0)for(i=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<i.length;)o.hasOwnProperty(e=i[t++])||(o[e]=this[e]);return n.config(o),n}function lr(o,t){return new this(o).div(t)}function ur(o){return new this(o).exp()}function dr(o){return E(o=new this(o),o.e+1,3)}function fr(){var o,t,e=new this(0);for(L=!1,o=0;o<arguments.length;)if(t=new this(arguments[o++]),t.d)e.d&&(e=e.plus(t.times(t)));else{if(t.s)return L=!0,new this(1/0);e=t}return L=!0,e.sqrt()}function Zn(o){return o instanceof Be||o&&o.toStringTag===Qn||!1}function _r(o){return new this(o).ln()}function hr(o,t){return new this(o).log(t)}function pr(o){return new this(o).log(2)}function mr(o){return new this(o).log(10)}function gr(){return to(this,arguments,-1)}function br(){return to(this,arguments,1)}function wr(o,t){return new this(o).mod(t)}function yr(o,t){return new this(o).mul(t)}function vr(o,t){return new this(o).pow(t)}function Pr(o){var t,e,i,n,r=0,a=new this(1),u=[];if(o===void 0?o=this.precision:Wt(o,1,_e),i=Math.ceil(o/N),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(i));r<i;)n=t[r],n>=429e7?t[r]=crypto.getRandomValues(new Uint32Array(1))[0]:u[r++]=n%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(i*=4);r<i;)n=t[r]+(t[r+1]<<8)+(t[r+2]<<16)+((t[r+3]&127)<<24),n>=214e7?crypto.randomBytes(4).copy(t,r):(u.push(n%1e7),r+=4);r=i/4}else throw Error(Vn);else for(;r<i;)u[r++]=Math.random()*1e7|0;for(i=u[--r],o%=N,i&&o&&(n=qt(10,N-o),u[r]=(i/n|0)*n);u[r]===0;r--)u.pop();if(r<0)e=0,u=[0];else{for(e=-1;u[0]===0;e-=N)u.shift();for(i=1,n=u[0];n>=10;n/=10)i++;i<N&&(e-=N-i)}return a.e=e,a.d=u,a}function Cr(o){return E(o=new this(o),o.e+1,this.rounding)}function Mr(o){return o=new this(o),o.d?o.d[0]?o.s:0*o.s:o.s||NaN}function kr(o){return new this(o).sin()}function Ar(o){return new this(o).sinh()}function Tr(o){return new this(o).sqrt()}function xr(o,t){return new this(o).sub(t)}function Sr(){var o=0,t=arguments,e=new this(t[o]);for(L=!1;e.s&&++o<t.length;)e=e.plus(t[o]);return L=!0,E(e,this.precision,this.rounding)}function Ir(o){return new this(o).tan()}function Rr(o){return new this(o).tanh()}function Or(o){return E(o=new this(o),o.e+1,1)}k[Symbol.for("nodejs.util.inspect.custom")]=k.toString;k[Symbol.toStringTag]="Decimal";var Be=k.constructor=no(Wi);ii=new Be(ii);ni=new Be(ni);var O=Be;function ge(o){let t=X.CoinAssist.isSuiCoin(o.coin_type_a),e=X.CoinAssist.isSuiCoin(o.coin_type_b);return{is_adjust_coin_a:t,is_adjust_coin_b:e}}function Fr(o,t){return O.ceil(O(o).div(1+t)).toString()}var Zt=class{static createCollectRewarderAndFeeParams(t,e,i,n,r,a){r===void 0&&(r=[...n]),a===void 0&&(a=[...n]);let u=(0,X.normalizeCoinType)(i.coin_type_a),d=(0,X.normalizeCoinType)(i.coin_type_b);if(i.collect_fee){let h=X.CoinAssist.buildCoinForAmount(e,r,BigInt(0),u,!1);r=h.remain_coins;let w=X.CoinAssist.buildCoinForAmount(e,a,BigInt(0),d,!1);a=w.remain_coins,e=t.Position.createCollectFeePayload({pool_id:i.pool_id,pos_id:i.pos_id,coin_type_a:i.coin_type_a,coin_type_b:i.coin_type_b},e,h.target_coin,w.target_coin)}let f=[];return i.rewarder_coin_types.forEach(h=>{switch((0,X.normalizeCoinType)(h)){case u:f.push(X.CoinAssist.buildCoinForAmount(e,r,BigInt(0),h,!1).target_coin);break;case d:f.push(X.CoinAssist.buildCoinForAmount(e,a,BigInt(0),h,!1).target_coin);break;default:f.push(X.CoinAssist.buildCoinForAmount(e,n,BigInt(0),h,!1).target_coin);break}}),e=t.Rewarder.createCollectRewarderPayload(i,e,f),e}static async adjustTransactionForGas(t,e,i,n){n.setSender(t.getSenderAddress());let r=X.CoinAssist.selectCoinAssetGreaterThanOrEqual(e,i).selected_coins,a=X.CoinAssist.calculateTotalBalance(e);if(r.length===0&&j("InsufficientBalance",`Insufficient balance exceed amount ${i} real amount ${a}`),a-i>1e9)return{fixAmount:i};let u=await t.FullClient.calculationTxGas(n);if(X.CoinAssist.selectCoinAssetGreaterThanOrEqual(e,BigInt(u),r.map(f=>f.coin_object_id)).selected_coins.length===0){let f=BigInt(u)+BigInt(500);if(a-i<f){i-=f,i<0&&j("InsufficientBalance","gas Insufficient balance");let h=new Gi.Transaction;return{fixAmount:i,newTx:h}}}return{fixAmount:i}}static async buildAddLiquidityFixTokenForGas(t,e,i,n,r,a,u){r=await this.buildAddLiquidityFixToken(t,e,i,r,a,u);let{is_adjust_coin_a:d}=ge(i),f=d?i.amount_a:i.amount_b,h=await this.adjustTransactionForGas(t,X.CoinAssist.getCoinAssets(d?i.coin_type_a:i.coin_type_b,e),BigInt(f),r),{fixAmount:w}=h,{newTx:P}=h;if(P!=null){let M,x;if(d)i.amount_a=Number(w),M=this.buildAddLiquidityFixTokenCoinInput(P,!i.fix_amount_a,w.toString(),i.slippage,i.coin_type_a,e,!1,!0),x=this.buildAddLiquidityFixTokenCoinInput(P,i.fix_amount_a,i.amount_b,i.slippage,i.coin_type_b,e,!1,!0);else return i.amount_b=Number(w),M=this.buildAddLiquidityFixTokenCoinInput(P,!i.fix_amount_a,i.amount_a,i.slippage,i.coin_type_a,e,!1,!0),x=this.buildAddLiquidityFixTokenCoinInput(P,i.fix_amount_a,w.toString(),i.slippage,i.coin_type_b,e,!1,!0),i=this.fixAddLiquidityFixTokenParams(i,n.slippage,n.cur_sqrt_price),r=await this.buildAddLiquidityFixTokenArgs(P,t,e,i,M,x),r}return r}static async buildAddLiquidityFixToken(t,e,i,n,r,a){n=n||new Gi.Transaction;let u,d;return r==null||a==null?(u=this.buildAddLiquidityFixTokenCoinInput(n,!i.fix_amount_a,i.amount_a,i.slippage,i.coin_type_a,e,!1,!0),d=this.buildAddLiquidityFixTokenCoinInput(n,i.fix_amount_a,i.amount_b,i.slippage,i.coin_type_b,e,!1,!0)):(u={target_coin:r,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},d={target_coin:a,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]}),n=this.buildAddLiquidityFixTokenArgs(n,t,e,i,u,d),n}static buildAddLiquidityFixTokenCoinInput(t,e,i,n,r,a,u=!0,d=!0){return e?X.CoinAssist.buildCoinForAmountInterval(t,a,{amount_second:BigInt(Fr(i,n)),amount_first:BigInt(i)},r,u,d):X.CoinAssist.buildCoinForAmount(t,a,BigInt(i),r,u,d)}static fixAddLiquidityFixTokenParams(t,e,i){let n=t.fix_amount_a?t.amount_a:t.amount_b,r=X.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(Number(t.tick_lower),Number(t.tick_upper),new oo.default(n),t.fix_amount_a,!0,e,i);return t.amount_a=t.fix_amount_a?t.amount_a:r.coin_amount_limit_a,t.amount_b=t.fix_amount_a?r.coin_amount_limit_b:t.amount_b,t}static buildAddLiquidityFixTokenArgs(t,e,i,n,r,a){let u=[n.coin_type_a,n.coin_type_b],d=n.is_open?"open_position_with_liquidity_by_fix_coin":"add_liquidity_by_fix_coin",{clmm_pool:f,integrate:h}=e.sdkOptions;n.is_open||(t=this.createCollectRewarderAndFeeParams(e,t,n,i,r.remain_coins,a.remain_coins));let w=(0,X.getPackagerConfigs)(f),P=n.is_open?[t.object(w.global_config_id),t.object(n.pool_id),t.pure.u32(Number((0,X.asUintN)(BigInt(n.tick_lower)).toString())),t.pure.u32(Number((0,X.asUintN)(BigInt(n.tick_upper)).toString())),r.target_coin,a.target_coin,t.pure.u64(n.amount_a),t.pure.u64(n.amount_b),t.pure.bool(n.fix_amount_a),t.object(X.CLOCK_ADDRESS)]:[t.object(w.global_config_id),t.object(n.pool_id),t.object(n.pos_id),r.target_coin,a.target_coin,t.pure.u64(n.amount_a),t.pure.u64(n.amount_b),t.pure.bool(n.fix_amount_a),t.object(X.CLOCK_ADDRESS)];return t.moveCall({target:`${h.published_at}::${Vt}::${d}`,typeArguments:u,arguments:P}),t}static checkCoinThreshold(t,e,i,n,r,a){e&&i.moveCall({target:`${t.sdkOptions.integrate.published_at}::${Oe}::check_coin_threshold`,typeArguments:[a],arguments:[n,i.pure.u64(r)]})}};var Xt=class o{static getDefaultSqrtPriceLimit(t){return new ro.default(t?H.MIN_SQRT_PRICE:H.MAX_SQRT_PRICE)}static getDefaultOtherAmountThreshold(t){return t?H.ZERO:H.U64_MAX}static async buildSwapTransactionForGas(t,e,i,n){let r=this.buildSwapTransaction(t,e,i);r.setSender(t.getSenderAddress());let a=await this.adjustTransactionForGas(t,H.CoinAssist.getCoinAssets(e.a2b?e.coin_type_a:e.coin_type_b,i),BigInt(e.by_amount_in?e.amount:e.amount_limit),r),{fixAmount:u,newTx:d}=a;if(d!==void 0){d.setSender(t.getSenderAddress()),e.by_amount_in?e.amount=u.toString():e.amount_limit=u.toString(),e=await this.fixSwapParams(t,e,n);let f=H.CoinAssist.buildCoinForAmount(r,i,e.a2b?BigInt(e.by_amount_in?e.amount:e.amount_limit):BigInt(0),e.coin_type_a),h=H.CoinAssist.buildCoinForAmount(r,i,e.a2b?BigInt(0):BigInt(e.by_amount_in?e.amount:e.amount_limit),e.coin_type_b);r=this.buildSwapTransactionArgs(d,e,t.sdkOptions,f,h)}return r}static buildSwapTransactionArgs(t,e,i,n,r){let{clmm_pool:a,integrate:u}=i,d=o.getDefaultSqrtPriceLimit(e.a2b),f=[e.coin_type_a,e.coin_type_b],{global_config_id:h}=(0,H.getPackagerConfigs)(a);h===void 0&&j("InvalidConfig","clmm.config.global_config_id is undefined");let w=e.swap_partner!==void 0,P=w?e.a2b?"swap_a2b_with_partner":"swap_b2a_with_partner":e.a2b?"swap_a2b":"swap_b2a",M=w?[t.object(h),t.object(e.pool_id),t.object(e.swap_partner),n.target_coin,r.target_coin,t.pure.bool(e.by_amount_in),t.pure.u64(e.amount),t.pure.u64(e.amount_limit),t.pure.u128(d.toString()),t.object(H.CLOCK_ADDRESS)]:[t.object(h),t.object(e.pool_id),n.target_coin,r.target_coin,t.pure.bool(e.by_amount_in),t.pure.u64(e.amount),t.pure.u64(e.amount_limit),t.pure.u128(d.toString()),t.object(H.CLOCK_ADDRESS)];return t.moveCall({target:`${u.published_at}::${Vt}::${P}`,typeArguments:f,arguments:M}),t}static async adjustTransactionForGas(t,e,i,n){n.setSender(t.getSenderAddress());let r=H.CoinAssist.selectCoinAssetGreaterThanOrEqual(e,i).selected_coins,a=H.CoinAssist.calculateTotalBalance(e);if(r.length===0&&j("InsufficientBalance",`Insufficient balance exceed amount ${i} real amount ${a}`),a-i>1e9)return{fixAmount:i};let u=await t.FullClient.calculationTxGas(n);if(H.CoinAssist.selectCoinAssetGreaterThanOrEqual(e,BigInt(u),r.map(f=>f.coin_object_id)).selected_coins.length===0){let f=BigInt(u)+BigInt(500);if(a-i<f){i-=f,i<0&&j("InsufficientBalance","gas Insufficient balance");let h=new ci.Transaction;return{fixAmount:i,newTx:h}}}return{fixAmount:i}}static buildSwapTransaction(t,e,i){let n=new ci.Transaction;n.setSender(t.getSenderAddress());let r=H.CoinAssist.buildCoinForAmount(n,i,e.a2b?BigInt(e.by_amount_in?e.amount:e.amount_limit):BigInt(0),e.coin_type_a,!1),a=H.CoinAssist.buildCoinForAmount(n,i,e.a2b?BigInt(0):BigInt(e.by_amount_in?e.amount:e.amount_limit),e.coin_type_b,!1);return n=this.buildSwapTransactionArgs(n,e,t.sdkOptions,r,a),n}static async fixSwapParams(t,e,i){let{current_pool:n}=i;try{let r=await t.Swap.preSwap({decimals_a:i.decimals_a,decimals_b:i.decimals_b,a2b:e.a2b,by_amount_in:e.by_amount_in,amount:e.amount,pool:n,current_sqrt_price:n.current_sqrt_price,coin_type_a:n.coin_type_a,coin_type_b:n.coin_type_b}),a=i.by_amount_in?r.estimated_amount_out:r.estimated_amount_in,u=(0,H.adjustForSlippage)(a,i.slippage,!i.by_amount_in);e.amount_limit=u.toString()}catch(r){me("InvalidConfig",r)}return e}static async buildSwapTransactionWithoutTransferCoinsForGas(t,e,i,n){let{tx:r,coin_ab_s:a}=o.buildSwapTransactionWithoutTransferCoins(t,e,i);r.setSender(t.getSenderAddress());let u=await o.adjustTransactionForGas(t,H.CoinAssist.getCoinAssets(e.a2b?e.coin_type_a:e.coin_type_b,i),BigInt(e.by_amount_in?e.amount:e.amount_limit),r),{fixAmount:d,newTx:f}=u;if(f!==void 0){f.setSender(t.getSenderAddress()),e.by_amount_in?e.amount=d.toString():e.amount_limit=d.toString(),e=await o.fixSwapParams(t,e,n);let h=H.CoinAssist.buildCoinForAmount(r,i,e.a2b?BigInt(e.by_amount_in?e.amount:e.amount_limit):BigInt(0),e.coin_type_a,!1,!0),w=H.CoinAssist.buildCoinForAmount(r,i,e.a2b?BigInt(0):BigInt(e.by_amount_in?e.amount:e.amount_limit),e.coin_type_b,!1,!0),P=o.buildSwapTransactionWithoutTransferCoinArgs(t,f,e,t.sdkOptions,h,w);r=P.tx,a=P.txRes}return{tx:r,coin_ab_s:a}}static buildSwapTransactionWithoutTransferCoins(t,e,i){let n=new ci.Transaction;n.setSender(t.getSenderAddress());let r=H.CoinAssist.buildCoinForAmount(n,i,e.a2b?BigInt(e.by_amount_in?e.amount:e.amount_limit):BigInt(0),e.coin_type_a,!1,!0),a=H.CoinAssist.buildCoinForAmount(n,i,e.a2b?BigInt(0):BigInt(e.by_amount_in?e.amount:e.amount_limit),e.coin_type_b,!1,!0),u=o.buildSwapTransactionWithoutTransferCoinArgs(t,n,e,t.sdkOptions,r,a);return{tx:u.tx,coin_ab_s:u.txRes}}static buildSwapTransactionWithoutTransferCoinArgs(t,e,i,n,r,a){let{clmm_pool:u,integrate:d}=n,f=o.getDefaultSqrtPriceLimit(i.a2b),{global_config_id:h}=(0,H.getPackagerConfigs)(u);h===void 0&&j("InvalidConfig","clmm.config.global_config_id is undefined");let w=i.swap_partner!==void 0,P=w?"swap_with_partner":"swap",M=w?Di:Oe,x=w?[e.object(h),e.object(i.pool_id),e.object(i.swap_partner),r.target_coin,a.target_coin,e.pure.bool(i.a2b),e.pure.bool(i.by_amount_in),e.pure.u64(i.amount),e.pure.u128(f.toString()),e.pure.bool(!1),e.object(H.CLOCK_ADDRESS)]:[e.object(h),e.object(i.pool_id),r.target_coin,a.target_coin,e.pure.bool(i.a2b),e.pure.bool(i.by_amount_in),e.pure.u64(i.amount),e.pure.u128(f.toString()),e.pure.bool(!1),e.object(H.CLOCK_ADDRESS)],S=[i.coin_type_a,i.coin_type_b],z=e.moveCall({target:`${d.published_at}::${M}::${P}`,typeArguments:S,arguments:x});if(i.by_amount_in){let $=i.a2b?i.coin_type_b:i.coin_type_a,V=i.a2b?z[1]:z[0],D=Number(i.amount_limit);Zt.checkCoinThreshold(t,i.by_amount_in,e,V,D,$)}return{tx:e,txRes:z}}};function Br(o,t,e){let i=t.mul(e).shln(64),n=t.shln(64).add(o.mul(e));return H.MathUtil.divRoundUp(i,n)}function Er(o,t,e){let i=t.mul(e).shln(64),n=t.shln(64).sub(o.mul(e));return H.MathUtil.divRoundUp(i,n)}function Nr(o,t,e){return e.sub(H.MathUtil.divRoundUp(o.shln(64),t))}function jr(o,t,e){return e.add(o.shln(64).div(t))}function qr(o){let t=new Ut.default(o);return t.lt(K.ZERO)?{bits:t.neg().xor(new Ut.default(2).pow(new Ut.default(64)).sub(new Ut.default(1))).add(new Ut.default(1)).toString()}:{bits:t.toString()}}function Vi(o){return{coin_type_a:o.coin_type_a,coin_type_b:o.coin_type_b,current_sqrt_price:new Ut.default(o.current_sqrt_price),current_tick_index:o.current_tick_index,fee_growth_global_a:new Ut.default(o.fee_growth_global_a),fee_growth_global_b:new Ut.default(o.fee_growth_global_b),fee_protocol_coin_a:new Ut.default(o.fee_protocol_coin_a),fee_protocol_coin_b:new Ut.default(o.fee_protocol_coin_b),fee_rate:new Ut.default(o.fee_rate),liquidity:new Ut.default(o.liquidity),tick_indexes:[],tick_spacing:Number(o.tick_spacing),ticks:[],collection_name:""}}function so(o,t,e,i,n,r){if(e===K.ZERO)return{amount_in:K.ZERO,amount_out:K.ZERO,next_sqrt_price:t,fee_amount:K.ZERO};let a=o.gte(t),u,d,f,h;if(r){let w=K.MathUtil.checkMulDivFloor(i,K.MathUtil.checkUnsignedSub(K.FEE_RATE_DENOMINATOR,n),K.FEE_RATE_DENOMINATOR,64),P=(0,K.getDeltaUpFromInput)(o,t,e,a);P.gt(w)?(u=w,h=K.MathUtil.checkUnsignedSub(i,w),f=(0,K.getNextSqrtPriceFromInput)(o,e,w,a)):(u=P,h=K.MathUtil.checkMulDivCeil(u,n,K.FEE_RATE_DENOMINATOR.sub(n),64),f=t),d=(0,K.getDeltaDownFromOutput)(o,f,e,a)}else{let w=(0,K.getDeltaDownFromOutput)(o,t,e,a);w.gt(i)?(d=i,f=(0,K.getNextSqrtPriceFromOutput)(o,e,i,a)):(d=w,f=t),u=(0,K.getDeltaUpFromInput)(o,f,e,a),h=K.MathUtil.checkMulDivCeil(u,n,K.FEE_RATE_DENOMINATOR.sub(n),64)}return{amount_in:u,amount_out:d,next_sqrt_price:f,fee_amount:h}}function Qi(o,t,e,i,n){let r=e,a=i.liquidity,{current_sqrt_price:u}=i,d={amount_in:K.ZERO,amount_out:K.ZERO,fee_amount:K.ZERO,ref_amount:K.ZERO,next_sqrt_price:K.ZERO,cross_tick_num:0},f,h,w=Xt.getDefaultSqrtPriceLimit(o);for(let P of n){if(o&&i.current_tick_index<P.index||!o&&i.current_tick_index>=P.index||P===null)continue;o&&w.gt(P.sqrt_price)||!o&&w.lt(P.sqrt_price)?f=w:f=P.sqrt_price;let M=so(u,f,a,r,i.fee_rate,t);if(M.amount_in.eq(K.ZERO)||(r=t?r.sub(M.amount_in.add(M.fee_amount)):r.sub(M.amount_out)),d.amount_in=d.amount_in.add(M.amount_in),d.amount_out=d.amount_out.add(M.amount_out),d.fee_amount=d.fee_amount.add(M.fee_amount),M.next_sqrt_price.eq(P.sqrt_price)?(h=P.liquidity_net.mul(new Ut.default(-1)),o?K.MathUtil.is_neg(h)?a=a.add(new Ut.default((0,K.asUintN)(BigInt(h.toString()),128))):a=a.add(h):K.MathUtil.is_neg(h)?a=a.sub(new Ut.default((0,K.asUintN)(BigInt(h.toString()),128))):a=a.sub(h),u=P.sqrt_price):u=M.next_sqrt_price,d.cross_tick_num+=1,r.eq(K.ZERO))break}return d.amount_in=d.amount_in.add(d.fee_amount),d.next_sqrt_price=u,d}function Dr(o,t,e){let i=(0,q.extractStructTagFromType)(o).name,n=(0,q.extractStructTagFromType)(t).name;return`${i}-${n}[${e}]`}function Ee(o){let t=(0,q.getMoveObjectType)(o),e=(0,q.extractStructTagFromType)(t),i=(0,q.getObjectFields)(o);i==null&&j("InvalidPoolObject",`Pool id ${(0,q.getObjectId)(o)} not exists.`,{[q.DETAILS_KEYS.METHOD_NAME]:"buildPool"});let n=[];i.rewarder_manager.fields.rewarders.forEach(a=>{let{emissions_per_second:u}=a.fields,d=q.MathUtil.fromX64(new Gt.default(u)),f=Math.floor(d.toNumber()*60*60*24);n.push({emissions_per_second:u,coin_type:(0,q.extractStructTagFromType)(a.fields.reward_coin.fields.name).source_address,growth_global:a.fields.growth_global,emissions_every_day:f})});let r={id:(0,q.getObjectId)(o),pool_type:t,coin_type_a:e.type_arguments[0],coin_type_b:e.type_arguments[1],coin_amount_a:i.coin_a,coin_amount_b:i.coin_b,current_sqrt_price:i.current_sqrt_price,current_tick_index:(0,q.asIntN)(BigInt(i.current_tick_index.fields.bits)),fee_growth_global_a:i.fee_growth_global_a,fee_growth_global_b:i.fee_growth_global_b,fee_protocol_coin_a:i.fee_protocol_coin_a,fee_protocol_coin_b:i.fee_protocol_coin_b,fee_rate:i.fee_rate,is_pause:i.is_pause,liquidity:i.liquidity,position_manager:{positions_handle:i.position_manager.fields.positions.fields.id.id,size:i.position_manager.fields.positions.fields.size},rewarder_infos:n,rewarder_last_updated_time:i.rewarder_manager.fields.last_updated_time,tick_spacing:i.tick_spacing,ticks_handle:i.tick_manager.fields.ticks.fields.id.id,uri:i.url,index:Number(i.index),name:""};return r.name=Dr(r.coin_type_a,r.coin_type_b,r.tick_spacing),r}function Ne(o){(o.error!=null||o.data?.content?.dataType!=="moveObject")&&j("InvalidPositionObject",`Position not exists. Get Position error:${o.error}`,{[q.DETAILS_KEYS.METHOD_NAME]:"buildPosition"});let t={creator:"",description:"",image_url:"",link:"",name:"",project_url:""},e={...t,pos_object_id:"",owner:"",type:"",coin_type_a:"",coin_type_b:"",liquidity:"",tick_lower_index:0,tick_upper_index:0,index:0,pool:"",reward_amount_owned_0:"0",reward_amount_owned_1:"0",reward_amount_owned_2:"0",reward_growth_inside_0:"0",reward_growth_inside_1:"0",reward_growth_inside_2:"0",fee_growth_inside_a:"0",fee_owned_a:"0",fee_growth_inside_b:"0",fee_owned_b:"0",position_status:"Exists"},i=(0,q.getObjectFields)(o);if(i){let a=(0,q.getMoveObjectType)(o),u=(0,q.getObjectOwner)(o);"nft"in i?(i=i.nft.fields,t.description=i.description,t.name=i.name,t.link=i.url):t=(0,q.buildNFT)(o),e={...t,pos_object_id:i.id.id,owner:u.AddressOwner,type:a,liquidity:i.liquidity,coin_type_a:i.coin_type_a.fields.name,coin_type_b:i.coin_type_b.fields.name,tick_lower_index:(0,q.asIntN)(BigInt(i.tick_lower_index.fields.bits)),tick_upper_index:(0,q.asIntN)(BigInt(i.tick_upper_index.fields.bits)),index:i.index,pool:i.pool,reward_amount_owned_0:"0",reward_amount_owned_1:"0",reward_amount_owned_2:"0",reward_growth_inside_0:"0",reward_growth_inside_1:"0",reward_growth_inside_2:"0",fee_growth_inside_a:"0",fee_owned_a:"0",fee_growth_inside_b:"0",fee_owned_b:"0",position_status:"Exists"}}let n=(0,q.getObjectDeletedResponse)(o);n&&(e.pos_object_id=n.objectId,e.position_status="Deleted");let r=(0,q.getObjectNotExistsResponse)(o);return r&&(e.pos_object_id=r,e.position_status="NotExists"),e}function je(o){let t={reward_amount_owned_0:"0",reward_amount_owned_1:"0",reward_amount_owned_2:"0",reward_growth_inside_0:"0",reward_growth_inside_1:"0",reward_growth_inside_2:"0"};o="fields"in o?o.fields:o,o.rewards.forEach((r,a)=>{let{amount_owned:u,growth_inside:d}="fields"in r?r.fields:r;a===0?(t.reward_amount_owned_0=u,t.reward_growth_inside_0=d):a===1?(t.reward_amount_owned_1=u,t.reward_growth_inside_1=d):a===2&&(t.reward_amount_owned_2=u,t.reward_growth_inside_2=d)});let e="fields"in o.tick_lower_index?o.tick_lower_index.fields.bits:o.tick_lower_index.bits,i="fields"in o.tick_upper_index?o.tick_upper_index.fields.bits:o.tick_upper_index.bits;return{liquidity:o.liquidity,tick_lower_index:(0,q.asIntN)(BigInt(e)),tick_upper_index:(0,q.asIntN)(BigInt(i)),...t,fee_growth_inside_a:o.fee_growth_inside_a,fee_owned_a:o.fee_owned_a,fee_growth_inside_b:o.fee_growth_inside_b,fee_owned_b:o.fee_owned_b,pos_object_id:o.position_id}}function qe(o){(o.error!=null||o.data?.content?.dataType!=="moveObject")&&j("InvalidTickObject",`Tick not exists. Get tick data error:${o.error}`,{[q.DETAILS_KEYS.METHOD_NAME]:"buildTickData"});let e=(0,q.getObjectFields)(o).value.fields.value.fields;return{object_id:(0,q.getObjectId)(o),index:(0,q.asIntN)(BigInt(e.index.fields.bits)),sqrt_price:new Gt.default(e.sqrt_price),liquidity_net:new Gt.default(e.liquidity_net.fields.bits),liquidity_gross:new Gt.default(e.liquidity_gross),fee_growth_outside_a:new Gt.default(e.fee_growth_outside_a),fee_growth_outside_b:new Gt.default(e.fee_growth_outside_b),rewarders_growth_outside:e.rewards_growth_outside}}function Ji(o){(!o||!o.index||!o.sqrt_price||!o.liquidity_net||!o.liquidity_gross||!o.fee_growth_outside_a||!o.fee_growth_outside_b)&&j("InvalidTickFields","Invalid tick fields.",{[q.DETAILS_KEYS.METHOD_NAME]:"buildTickDataByEvent"});let t=(0,q.asIntN)(BigInt(o.index.bits)),e=new Gt.default(o.sqrt_price),i=new Gt.default(o.liquidity_net.bits),n=new Gt.default(o.liquidity_gross),r=new Gt.default(o.fee_growth_outside_a),a=new Gt.default(o.fee_growth_outside_b),u=o.rewards_growth_outside||[];return{object_id:"",index:t,sqrt_price:e,liquidity_net:i,liquidity_gross:n,fee_growth_outside_a:r,fee_growth_outside_b:a,rewarders_growth_outside:u}}function Lr(o,t){return`Cetus LP | Pool${o}-${t}`}function Xi(o,t,e){let i=[],{timestampMs:n,events:r}=o,a=["AddLiquidityEvent","RemoveLiquidityEvent","CollectFeeEvent","CollectRewardEvent","CollectRewardV2Event","HarvestEvent"];return r?.forEach((u,d)=>{let f=(0,q.extractStructTagFromType)(u.type).name;if(a.includes(f)){let h={tx_digest:u.id.txDigest,package_id:u.packageId,transaction_module:u.transactionModule,sender:u.sender,type:u.type,timestamp_ms:n||"0",parsed_json:u.parsedJson,index:`${t}_${d}`};switch(f){case"CollectFeeEvent":e.includes(h.parsed_json.position)&&((0,q.d)(h.parsed_json.amount_a).gt(0)||(0,q.d)(h.parsed_json.amount_b).gt(0))&&i.push(h);break;case"RemoveLiquidityEvent":case"AddLiquidityEvent":((0,q.d)(h.parsed_json.amount_a).gt(0)||(0,q.d)(h.parsed_json.amount_b).gt(0))&&i.push(h);break;case"CollectRewardEvent":case"HarvestEvent":case"CollectRewardV2Event":(e.includes(h.parsed_json.position)||e.includes(h.parsed_json.wrapped_position_id))&&(0,q.d)(h.parsed_json.amount).gt(0)&&i.push(h);break;default:break}}}),i}function Yi(o,t,e,i){let n=[],{timestampMs:r,events:a}=o;return a?.forEach((u,d)=>{let{name:f,address:h}=(0,q.extractStructTagFromType)(u.type);if(Ui.includes(f)&&h===e&&i===u.parsedJson.pool){let w={tx:u.id.txDigest,sender:u.sender,type:u.type,block_time:r||"0",index:`${t}_${d}`,parsed_json:u.parsedJson};n.push(w)}}),n}function De(o,t,e,i){t.moveCall({target:`${o.sdkOptions.integrate.published_at}::${Li}::transfer_coin_to_sender`,typeArguments:[i],arguments:[e]})}function tn(o,t,e,i,n){n!=null?t.transferObjects([e],t.pure.address(n)):De(o,t,e,i)}var A=require("@cetusprotocol/common-sdk"),Le=class{constructor(t){this._sdk=t}get sdk(){return this._sdk}async getPositionList(t,e="all"){let i={data:[],has_next_page:!0},n=await this._sdk.FullClient.getDynamicFieldsByPage(t,e);i.has_next_page=n.has_next_page,i.next_cursor=n.next_cursor;let r=n.data.map(u=>(u.error!=null&&j("InvalidConfig",`when getPositionList get position objects error: ${u.error}, please check the rpc, contracts address config and position id.`,{[A.DETAILS_KEYS.METHOD_NAME]:"getPositionList"}),u.name.value)),a=await this._sdk.Position.getSimplePositionList(r);return i.data=a,i}async getPoolImmutablesWithPage(t="all",e=!1){let{package_id:i}=this._sdk.sdkOptions.clmm_pool,n=[],r={data:[],has_next_page:!1},a=t==="all",u=`${i}_getPoolImmutables`;if(a){let d=this._sdk.getCache(u,e);d&&n.push(...d)}if(n.length===0)try{let d=`${i}::factory::CreatePoolEvent`,f=await this._sdk.FullClient.queryEventsByPage({MoveEventType:d},t);r.has_next_page=f.has_next_page,r.next_cursor=f.next_cursor,f.data.forEach(h=>{let w=h.parsedJson;w&&n.push({id:w.pool_id,tick_spacing:w.tick_spacing,coin_type_a:(0,A.extractStructTagFromType)(w.coin_type_a).full_address,coin_type_b:(0,A.extractStructTagFromType)(w.coin_type_b).full_address})})}catch(d){console.log("getPoolImmutables",d)}return r.data=n,a&&this._sdk.updateCache(`${i}_getPoolImmutables`,n,A.CACHE_TIME_24H),r}async getPoolsWithPage(t="all",e=!1){let i={data:[],has_next_page:!1},n=await this.getPoolImmutablesWithPage(t,e),r=await this._sdk.FullClient.batchGetObjects(n.data.map(a=>a.id),{showContent:!0,showType:!0});for(let a of r){(a.error!=null||a.data?.content?.dataType!=="moveObject")&&j("InvalidPoolObject",`getPoolWithPages error code: ${a.error?.code??"unknown error"}, please check config and object ids`,{[A.DETAILS_KEYS.METHOD_NAME]:"getPoolsWithPage"});let u=Ee(a);i.data.push(u);let d=`${u.id}_getPoolObject`;this._sdk.updateCache(d,u,A.CACHE_TIME_24H)}return i.has_next_page=n.has_next_page,i.next_cursor=n.next_cursor,i}async getAssignPools(t){if(t.length===0)return[];let e=[],i=await this._sdk.FullClient.batchGetObjects(t,{showContent:!0,showType:!0});for(let n of i){(n.error!=null||n.data?.content?.dataType!=="moveObject")&&j("InvalidPoolObject",`getPools error code: ${n.error?.code??"unknown error"}, please check config and object ids`,{[A.DETAILS_KEYS.METHOD_NAME]:"getAssignPools"});let r=Ee(n);e.push(r);let a=`${r.id}_getPoolObject`;this._sdk.updateCache(a,r,A.CACHE_TIME_24H)}return e}async getPool(t,e=!0){let i=`${t}_getPoolObject`,n=this._sdk.getCache(i,e);if(n!==void 0)return n;let r=await this._sdk.FullClient.getObject({id:t,options:{showType:!0,showContent:!0}});(r.error!=null||r.data?.content?.dataType!=="moveObject")&&j("InvalidPoolObject",`getPool error code: ${r.error?.code??"unknown error"}, please check config and object id`,{[A.DETAILS_KEYS.METHOD_NAME]:"getPool"});let a=Ee(r);return this._sdk.updateCache(i,a),a}async getPoolByCoins(t,e){if(t.length===0)return[];for(let d=0;d<t.length;d++)t[d]==="0x2::sui::SUI"&&(t[d]="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI");let i=this._sdk.sdkOptions.stats_pools_url;i||j("StatsPoolsUrlNotSet","statsPoolsUrl is not set in the sdk options.",{[A.DETAILS_KEYS.METHOD_NAME]:"getPoolByCoins"}),i+=`?order_by=-fees&limit=100&has_mining=true&has_farming=true&no_incentives=true&display_all_pools=true&coin_type=${t.join(",")}`;let n=await fetch(i),r;try{r=await n.json()}catch(d){me("FetchError",d,{[A.DETAILS_KEYS.METHOD_NAME]:"getPoolByCoins",[A.DETAILS_KEYS.REQUEST_PARAMS]:i})}let a=r.data.lp_list,u=[];for(let d of a)t.includes(d.coin_a_address)&&t.includes(d.coin_b_address)&&(e!=null?d.object.feeRate===e&&u.push(d.address):u.push(d.address));return u.length>0?await this.getAssignPools(u):[]}async createPoolPayload(t,e){if((0,A.isSortedSymbols)((0,be.normalizeSuiAddress)(t.coin_type_a),(0,be.normalizeSuiAddress)(t.coin_type_b))){let i=t.coin_type_b;t.coin_type_b=t.coin_type_a,t.coin_type_a=i;let n=t.metadata_b;t.metadata_b=t.metadata_a,t.metadata_a=n}return await this.createPoolAndAddLiquidity(t,e)}async createPoolRowPayload(t,e){if((0,A.isSortedSymbols)((0,be.normalizeSuiAddress)(t.coin_type_a),(0,be.normalizeSuiAddress)(t.coin_type_b))){let i=t.coin_type_b;t.coin_type_b=t.coin_type_a,t.coin_type_a=i;let n=t.metadata_b;t.metadata_b=t.metadata_a,t.metadata_a=n}return await this.createPoolAndAddLiquidityRow(t,e)}async getClmmConfigs(t=!1){let{package_id:e}=this._sdk.sdkOptions.clmm_pool,i=`${e}_getInitEvent`,n=this._sdk.getCache(i,t);if(n!==void 0)return n;let r=await this._sdk.FullClient.getObject({id:e,options:{showPreviousTransaction:!0}}),a=(0,A.getObjectPreviousTransactionDigest)(r),u=(await this._sdk.FullClient.queryEventsByPage({Transaction:a})).data,d={pools_id:"",global_config_id:"",global_vault_id:"",admin_cap_id:""};return u.length>0&&(u.forEach(f=>{let h=f.parsedJson;if(f.type)switch((0,A.extractStructTagFromType)(f.type).full_address){case`${e}::config::InitConfigEvent`:d.global_config_id=h.global_config_id,d.admin_cap_id=h.admin_cap_id;break;case`${e}::factory::InitFactoryEvent`:d.pools_id=h.pools_id;break;case`${e}::rewarder::RewarderInitEvent`:d.global_vault_id=h.global_vault_id;break;case`${e}::partner::InitPartnerEvent`:d.partners_id=h.partners_id;break;default:break}}),this._sdk.updateCache(i,d,A.CACHE_TIME_24H)),d}async getPoolTransactionList({pool_id:t,pagination_args:e,order:i="descending",full_rpc_url:n}){let{FullClient:r,sdkOptions:a}=this._sdk,u;n?u=(0,A.createFullClient)(new ao.SuiClient({url:n})):u=r;let d={data:[],has_next_page:!1},f=50,h=e,w=e.limit||10;do{let P=await u.queryTransactionBlocksByPage({ChangedObject:t},{...h,limit:50},i);P.data.forEach((M,x)=>{d.next_cursor=P.next_cursor;let S=Yi(M,x,a.clmm_pool.package_id,t);d.data=[...d.data,...S]}),d.has_next_page=P.has_next_page,d.next_cursor=P.next_cursor,h.cursor=P.next_cursor}while(d.data.length<w&&d.has_next_page);return d.data.length>w&&(d.data=d.data.slice(0,w),d.next_cursor=d.data[d.data.length-1].tx),d}async calculateCreatePoolWithPrice(t){let{current_price:e,slippage:i,tick_spacing:n,add_mode_params:r,price_base_coin:a,coin_decimals_a:u,coin_decimals_b:d}=t,f=A.TickMath.priceToSqrtPriceX64(a==="coin_a"?(0,A.d)(e):(0,A.d)(1).div(e),u,d),h=0,w=0;if(r.is_full_range)h=A.TickUtil.getMinIndex(n),w=A.TickUtil.getMaxIndex(n);else{let{min_price:D,max_price:W}=r;h=A.TickMath.priceToInitializeTickIndex(a==="coin_a"?(0,A.d)(D):(0,A.d)(1).div(W),u,d,n),w=A.TickMath.priceToInitializeTickIndex(a==="coin_a"?(0,A.d)(W):(0,A.d)(1).div(D),u,d,n)}let{coin_amount:P,fix_amount_a:M}=t,{coin_amount_limit_a:x,coin_amount_limit_b:S,liquidity_amount:z,coin_amount_a:$,coin_amount_b:V}=A.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(h,w,new co.default(P),M,!0,i,f);return{coin_amount_a:$,coin_amount_b:V,coin_amount_limit_a:x,coin_amount_limit_b:S,liquidity:z,initialize_sqrt_price:f.toString(),tick_lower:h,tick_upper:w,fix_amount_a:M}}async createPoolAndAddLiquidity(t,e){e=e||new Te.Transaction,e.setSender(this.sdk.getSenderAddress());let{integrate:i,clmm_pool:n}=this.sdk.sdkOptions,r=(0,A.getPackagerConfigs)(n),a=r.global_config_id,u=r.pools_id,d=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),f=A.CoinAssist.buildCoinForAmount(e,d,BigInt(t.amount_a),t.coin_type_a,!1,!0),h=A.CoinAssist.buildCoinForAmount(e,d,BigInt(t.amount_b),t.coin_type_b,!1,!0),w=[e.object(a),e.object(u),e.pure.u32(t.tick_spacing),e.pure.u128(t.initialize_sqrt_price),e.pure.string(t.uri),e.pure.u32(Number((0,A.asUintN)(BigInt(t.tick_lower)).toString())),e.pure.u32(Number((0,A.asUintN)(BigInt(t.tick_upper)).toString())),f.target_coin,h.target_coin,e.object(t.metadata_a),e.object(t.metadata_b),e.pure.bool(t.fix_amount_a),e.object(A.CLOCK_ADDRESS)];return e.moveCall({target:`${i.published_at}::pool_creator_v2::create_pool_v2`,typeArguments:[t.coin_type_a,t.coin_type_b],arguments:w}),De(this._sdk,e,f.target_coin,t.coin_type_a),De(this._sdk,e,h.target_coin,t.coin_type_b),e}async createPoolAndAddLiquidityRow(t,e){e=e||new Te.Transaction;let{clmm_pool:i}=this.sdk.sdkOptions,n=(0,A.getPackagerConfigs)(i),r=n.global_config_id,a=n.pools_id,u=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress()),d=A.CoinAssist.buildCoinForAmount(e,u,BigInt(t.amount_a),t.coin_type_a,!1,!0),f=A.CoinAssist.buildCoinForAmount(e,u,BigInt(t.amount_b),t.coin_type_b,!1,!0),h=[e.object(r),e.object(a),e.pure.u32(t.tick_spacing),e.pure.u128(t.initialize_sqrt_price),e.pure.string(t.uri),e.pure.u32(Number((0,A.asUintN)(BigInt(t.tick_lower)).toString())),e.pure.u32(Number((0,A.asUintN)(BigInt(t.tick_upper)).toString())),d.target_coin,f.target_coin,e.object(t.metadata_a),e.object(t.metadata_b),e.pure.bool(t.fix_amount_a),e.object(A.CLOCK_ADDRESS)],w=e.moveCall({target:`${i.published_at}::pool_creator::create_pool_v2`,typeArguments:[t.coin_type_a,t.coin_type_b],arguments:h});return{tx:e,pos_id:w[0],remain_coin_a:w[1],remain_coin_b:w[2],remain_coin_type_a:t.coin_type_a,remain_coin_type_b:t.coin_type_b}}async createPoolWithPriceReturnPositionPayload(t,e){let{coin_type_a:i,coin_type_b:n,tick_spacing:r,uri:a,calculate_result:u}=t,{initialize_sqrt_price:d,tick_lower:f,tick_upper:h,liquidity:w,coin_amount_a:P,coin_amount_b:M,fix_amount_a:x,coin_amount_limit_a:S,coin_amount_limit_b:z}=u,$=await this._sdk.FullClient.fetchCoinMetadata(i),V=await this._sdk.FullClient.fetchCoinMetadata(n);if($===null)return j("FetchError",`fetch coin ${i} metadata failed`,{[A.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[A.DETAILS_KEYS.REQUEST_PARAMS]:t});if(V===null)return j("FetchError",`fetch coin ${n} metadata failed`,{[A.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[A.DETAILS_KEYS.REQUEST_PARAMS]:t});let D=$.id,W=V.id;return this.createPoolRowPayload({tick_spacing:r,initialize_sqrt_price:d,uri:a||"",coin_type_a:i,coin_type_b:n,amount_a:x?P:S,amount_b:x?z:M,fix_amount_a:x,tick_lower:f,tick_upper:h,metadata_a:D,metadata_b:W},e)}async createPoolWithPricePayload(t){let{coin_type_a:e,coin_type_b:i,tick_spacing:n,uri:r,calculate_result:a}=t,{initialize_sqrt_price:u,tick_lower:d,tick_upper:f,liquidity:h,coin_amount_a:w,coin_amount_b:P,fix_amount_a:M,coin_amount_limit_a:x,coin_amount_limit_b:S}=a,z=await this._sdk.FullClient.fetchCoinMetadata(e),$=await this._sdk.FullClient.fetchCoinMetadata(i);if(z===null)return j("FetchError",`fetch coin ${e} metadata failed`,{[A.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[A.DETAILS_KEYS.REQUEST_PARAMS]:t});if($===null)return j("FetchError",`fetch coin ${i} metadata failed`,{[A.DETAILS_KEYS.METHOD_NAME]:"createPoolAndAddLiquidityWithPrice",[A.DETAILS_KEYS.REQUEST_PARAMS]:t});let V=z.id,D=$.id;return this.createPoolPayload({tick_spacing:n,initialize_sqrt_price:u,uri:r||"",coin_type_a:e,coin_type_b:i,amount_a:M?w:x,amount_b:M?S:P,fix_amount_a:M,tick_lower:d,tick_upper:f,metadata_a:V,metadata_b:D})}async fetchTicks(t){let e=[],i=[];for(;;){let r=await this.getTicks({pool_id:t.pool_id,coin_type_a:t.coin_type_a,coin_type_b:t.coin_type_b,start:i,limit:512});if(e=[...e,...r],r.length<512)break;i=[Number((0,A.asUintN)(BigInt(r[r.length-1].index)))]}return e}async getTicks(t){let{integrate:e}=this.sdk.sdkOptions,i=[],n=[t.coin_type_a,t.coin_type_b],r=new Te.Transaction,a=r.makeMoveVec({elements:t.start.map(f=>r.pure.u32(f)),type:"u32"}),u=[r.object(t.pool_id),a,r.pure.u64(t.limit.toString())];r.moveCall({target:`${e.published_at}::${Qt}::fetch_ticks`,arguments:u,typeArguments:n});let d=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:r,sender:(0,be.normalizeSuiAddress)("0x0")});return d.error!=null&&j("InvalidTickObjectId",`getTicks error code: ${d.error??"unknown error"}, please check config and tick object ids`,{[A.DETAILS_KEYS.METHOD_NAME]:"getTicks",[A.DETAILS_KEYS.REQUEST_PARAMS]:t}),d.events?.forEach(f=>{(0,A.extractStructTagFromType)(f.type).name==="FetchTicksResultEvent"&&f.parsedJson.ticks.forEach(h=>{i.push(Ji(h))})}),i}async fetchPositionRewardList(t){let{integrate:e}=this.sdk.sdkOptions,i=[],n=[],r=512;for(;;){let a=[t.coin_type_a,t.coin_type_b],u=new Te.Transaction,d=u.pure.vector("id",n.map(P=>P)),f=[u.object(t.pool_id),d,u.pure.u64(r)];u.moveCall({target:`${e.published_at}::${Qt}::fetch_positions`,arguments:f,typeArguments:a});let h=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:u,sender:(0,be.normalizeSuiAddress)("0x0")});h.error!=null&&j("InvalidPositionRewardObject",`fetch position reward error code: ${h.error??"unknown error"}, please check config and tick object ids`,{[A.DETAILS_KEYS.METHOD_NAME]:"fetchPositionRewardList",[A.DETAILS_KEYS.REQUEST_PARAMS]:t});let w=[];if(h?.events?.forEach(P=>{(0,A.extractStructTagFromType)(P.type).name==="FetchPositionsEvent"&&P.parsedJson.positions.forEach(M=>{let x=je(M);w.push(x)})}),i.push(...w),w.length<r)break;n=[w[w.length-1].pos_object_id]}return i}async fetchTicksByRpc(t){let e=[],i=null,n=50;for(;;){let r=[],a=await this.sdk.FullClient.getDynamicFields({parentId:t,cursor:i,limit:n});if(i=a.nextCursor,a.data.forEach(u=>{(0,A.extractStructTagFromType)(u.objectType).module==="skip_list"&&r.push(u.objectId)}),e=[...e,...await this.getTicksByRpc(r)],!a.hasNextPage)break}return e}async getTicksByRpc(t){let e=[],i=await this.sdk.FullClient.batchGetObjects(t,{showContent:!0,showType:!0});for(let n of i){(n.error!=null||n.data?.content?.dataType!=="moveObject")&&j("InvalidTickObjectId",`getTicksByRpc error code: ${n.error?.code??"unknown error"}, please check config and tick object ids`,{[A.DETAILS_KEYS.METHOD_NAME]:"getTicksByRpc"});let r=qe(n);r!=null&&e.push(r)}return e}async getTickDataByIndex(t,e){let i={type:"u64",value:(0,A.asUintN)(BigInt((0,A.tickScore)(e).toString())).toString()},n=await this.sdk.FullClient.getDynamicFieldObject({parentId:t,name:i});return(n.error!=null||n.data?.content?.dataType!=="moveObject")&&j("InvalidTickIndex",`get tick by index: ${e} error: ${n.error}`,{[A.DETAILS_KEYS.METHOD_NAME]:"getTickDataByIndex"}),qe(n)}async getTickDataByObjectId(t){let e=await this.sdk.FullClient.getObject({id:t,options:{showContent:!0}});return(e.error!=null||e.data?.content?.dataType!=="moveObject")&&j("InvalidTickObjectId",`getTicksByRpc error code: ${e.error?.code??"unknown error"}, please check config and tick object ids`,{[A.DETAILS_KEYS.METHOD_NAME]:"getTickDataByObjectId"}),qe(e)}async getPartnerRefFeeAmount(t,e=!0){let i=await this._sdk.FullClient.batchGetObjects([t],{showOwner:!0,showContent:!0,showDisplay:e,showType:!0});i[0].data?.content?.dataType!=="moveObject"&&j("NotFoundPartnerObject",`get partner by object id: ${t} error: ${i[0].error}`,{[A.DETAILS_KEYS.METHOD_NAME]:"getPartnerRefFeeAmount"});let n=i[0].data.content.fields.balances,r=await this._sdk.FullClient.getDynamicFieldsByPage(n.fields.id.id),a=[];r.data.forEach(f=>{f.objectId!=null&&a.push(f.objectId)});let u=[];return(await this._sdk.FullClient.batchGetObjects(a,{showOwner:!0,showContent:!0,showDisplay:e,showType:!0})).forEach(f=>{(f.error!=null||f.data?.content?.dataType!=="moveObject")&&j("InvalidPartnerRefFeeFields",`get coin by object id: ${f.data.objectId} error: ${f.error}`,{[A.DETAILS_KEYS.METHOD_NAME]:"getPartnerRefFeeAmount"});let h={coin_type:f.data.content.fields.name,coin_object_id:f.data.objectId,balance:BigInt(f.data.content.fields.value)};u.push(h)}),u}async claimPartnerRefFeePayload(t,e,i){let n=new Te.Transaction,{clmm_pool:r}=this.sdk.sdkOptions,{global_config_id:a}=(0,A.getPackagerConfigs)(r),u=[i],d=[n.object(a),n.object(t),n.object(e)];return n.moveCall({target:`${r.published_at}::${qi}::claim_ref_fee`,arguments:d,typeArguments:u}),n}};var lo=require("@mysten/sui/client"),oe=require("@mysten/sui/transactions"),li=require("@mysten/sui/utils"),$e=ce(ee()),I=require("@cetusprotocol/common-sdk");var Ue=class{constructor(t){this._sdk=t}get sdk(){return this._sdk}buildPositionType(){return`${this._sdk.sdkOptions.clmm_pool.package_id}::position::Position`}async getPositionTransactionList({pos_id:t,origin_pos_id:e,full_rpc_url:i,pagination_args:n="all",order:r="ascending"}){let{FullClient:a}=this._sdk,u=[t];e&&u.push(e);let d;i?d=(0,I.createFullClient)(new lo.SuiClient({url:i})):d=a;let f={data:[],has_next_page:!1};try{let h=await d.queryTransactionBlocksByPage({ChangedObject:t},n,r);return h.data.forEach((w,P)=>{let M=Xi(w,P,u);f.data=[...f.data,...M]}),f.has_next_page=h.has_next_page,f.next_cursor=h.next_cursor,f}catch(h){me("FetchError",h,{[I.DETAILS_KEYS.METHOD_NAME]:"getPositionTransactionList"})}return f}async getPositionList(t,e=[],i=!0){let n=[],r=await this._sdk.FullClient.getOwnedObjectsByPage(t,{options:{showType:!0,showContent:!0,showDisplay:i,showOwner:!0},filter:{Package:this._sdk.sdkOptions.clmm_pool.package_id}}),a=e.length>0;for(let u of r.data)if((0,I.extractStructTagFromType)(u.data.type).full_address===this.buildPositionType()){let f=Ne(u),h=`${f.pos_object_id}_getPositionList`;this._sdk.updateCache(h,f),a?e.includes(f.pool)&&n.push(f):n.push(f)}return n}async getPosition(t,e,i=!0,n=!0){let r=await this.getSimplePosition(e,n);return i&&(r=await this.updatePositionRewarders(t,r)),r}async getPositionById(t,e=!0,i=!0){let n=await this.getSimplePosition(t,i);if(e){let r=await this._sdk.Pool.getPool(n.pool,!1);return await this.updatePositionRewarders(r.position_manager.positions_handle,n)}return n}async getSimplePosition(t,e=!0){let i=`${t}_getPositionList`,n=this.getSimplePositionByCache(t);if(n===void 0){let r=await this.sdk.FullClient.getObject({id:t,options:{showContent:!0,showType:!0,showDisplay:e,showOwner:!0}});n=Ne(r),this._sdk.updateCache(i,n)}return n}getSimplePositionByCache(t){let e=`${t}_getPositionList`;return this._sdk.getCache(e)}async getSimplePositionList(t,e=!0){let i=[],n=[];return t.forEach(r=>{let a=this.getSimplePositionByCache(r);a?i.push(a):n.push(r)}),n.length>0&&(await this._sdk.FullClient.batchGetObjects(n,{showOwner:!0,showContent:!0,showDisplay:e,showType:!0})).forEach(a=>{if(a.error==null){let u=Ne(a);i.push(u);let d=`${u.pos_object_id}_getPositionList`;this._sdk.updateCache(d,u)}}),i}async updatePositionRewarders(t,e){let i=await this.getPositionRewarders(t,e.pos_object_id);return{...e,...i}}async getPositionRewarders(t,e){try{let i=await this._sdk.FullClient.getDynamicFieldObject({parentId:t,name:{type:"0x2::object::ID",value:e}}),r=(0,I.getObjectFields)(i.data).value.fields.value;return je(r)}catch(i){console.log(i);return}}buildFetchPosFee(t,e){let{clmm_pool:i,integrate:n}=this.sdk.sdkOptions,r=[t.coin_type_a,t.coin_type_b],a=[e.object((0,I.getPackagerConfigs)(i).global_config_id),e.object(t.pool_id),e.pure.address(t.position_id)];e.moveCall({target:`${n.published_at}::${Qt}::fetch_position_fees`,arguments:a,typeArguments:r})}parsedPosFeeData(t){let e={},i=t.events?.filter(n=>n.type.includes("fetcher_script::FetchPositionFeesEvent"));for(let n=0;n<i.length;n+=1){let{parsedJson:r}=i[n],a={position_id:r.position_id,fee_owned_a:r.fee_owned_a,fee_owned_b:r.fee_owned_b};e[r.position_id]=a}return e}async fetchPosFeeAmount(t){let{clmm_pool:e,integrate:i}=this.sdk.sdkOptions,n=new oe.Transaction;for(let d of t)this.buildFetchPosFee(d,n);let r=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:n,sender:(0,li.normalizeSuiAddress)("0x0")});r.error!=null&&j("InvalidPoolObject",`fetch position fee error code: ${r.error??"unknown error"}, please check config and position and pool object ids`,{[I.DETAILS_KEYS.METHOD_NAME]:"fetchPosFeeAmount"});let a=[],u=this.parsedPosFeeData(r);for(let d=0;d<t.length;d+=1){let f=u[t[d].position_id];if(f){let h={fee_owned_a:f.fee_owned_a,fee_owned_b:f.fee_owned_b,position_id:t[d].position_id};a.push(h)}}return a}async batchFetchPositionFees(t){let e=[];for(let n of t){let r=await this._sdk.Position.getPositionById(n,!1),a=await this._sdk.Pool.getPool(r.pool,!1);e.push({pool_id:a.id,position_id:r.pos_object_id,coin_type_a:a.coin_type_a,coin_type_b:a.coin_type_b})}let i={};if(e.length>0){let n=await this.fetchPosFeeAmount(e);for(let r of n)i[r.position_id]=r;return i}return i}async createAddLiquidityFixTokenPayload(t,e,i,n,r){let a=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());if(e){let{is_adjust_coin_a:u,is_adjust_coin_b:d}=ge(t);if(t=t,t.fix_amount_a&&u||!t.fix_amount_a&&d)return i=await Zt.buildAddLiquidityFixTokenForGas(this._sdk,a,t,e,i,n,r),i}return Zt.buildAddLiquidityFixToken(this._sdk,a,t,i,n,r)}async createAddLiquidityPayload(t,e,i,n){let{integrate:r,clmm_pool:a}=this._sdk.sdkOptions,u=(0,I.asUintN)(BigInt(t.tick_lower)).toString(),d=(0,I.asUintN)(BigInt(t.tick_upper)).toString(),f=[t.coin_type_a,t.coin_type_b];e=e||new oe.Transaction;let h=!(0,li.isValidSuiObjectId)(t.pos_id),w=BigInt(t.max_amount_a),P=BigInt(t.max_amount_b),M,x;if(i==null||n==null){let S=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());M=I.CoinAssist.buildCoinForAmount(e,S,w,t.coin_type_a,!1,!0),x=I.CoinAssist.buildCoinForAmount(e,S,P,t.coin_type_b,!1,!0)}else M={target_coin:i,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},x={target_coin:n,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]};if(h)e.moveCall({target:`${r.published_at}::${Vt}::open_position_with_liquidity`,typeArguments:f,arguments:[e.object((0,I.getPackagerConfigs)(a).global_config_id),e.object(t.pool_id),e.pure.u32(Number(u)),e.pure.u32(Number(d)),M.target_coin,x.target_coin,e.pure.u64(t.max_amount_a),e.pure.u64(t.max_amount_b),e.pure.u128(t.delta_liquidity),e.object(I.CLOCK_ADDRESS)]});else{let S=await this._sdk.FullClient.getOwnerCoinAssets(this._sdk.getSenderAddress());e=Zt.createCollectRewarderAndFeeParams(this._sdk,e,t,S,M.remain_coins,x.remain_coins),e.moveCall({target:`${r.published_at}::${Vt}::add_liquidity`,typeArguments:f,arguments:[e.object((0,I.getPackagerConfigs)(a).global_config_id),e.object(t.pool_id),e.object(t.pos_id),M.target_coin,x.target_coin,e.pure.u64(t.max_amount_a),e.pure.u64(t.max_amount_b),e.pure.u128(t.delta_liquidity),e.object(I.CLOCK_ADDRESS)]})}return e}async removeLiquidityPayload(t,e){let{clmm_pool:i,integrate:n}=this.sdk.sdkOptions,r="remove_liquidity";e=e||new oe.Transaction;let a=[t.coin_type_a,t.coin_type_b],u=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());e=Zt.createCollectRewarderAndFeeParams(this._sdk,e,t,u);let d=[e.object((0,I.getPackagerConfigs)(i).global_config_id),e.object(t.pool_id),e.object(t.pos_id),e.pure.u128(t.delta_liquidity),e.pure.u64(t.min_amount_a),e.pure.u64(t.min_amount_b),e.object(I.CLOCK_ADDRESS)];return e.moveCall({target:`${n.published_at}::${Me}::${r}`,typeArguments:a,arguments:d}),e}async closePositionPayload(t,e){let{clmm_pool:i,integrate:n}=this.sdk.sdkOptions;e=e||new oe.Transaction;let r=[t.coin_type_a,t.coin_type_b],a=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());return e=Zt.createCollectRewarderAndFeeParams(this._sdk,e,t,a),e.moveCall({target:`${n.published_at}::${Me}::close_position`,typeArguments:r,arguments:[e.object((0,I.getPackagerConfigs)(i).global_config_id),e.object(t.pool_id),e.object(t.pos_id),e.pure.u64(t.min_amount_a),e.pure.u64(t.min_amount_b),e.object(I.CLOCK_ADDRESS)]}),e}openPositionPayload(t,e){let{clmm_pool:i,integrate:n}=this.sdk.sdkOptions;e=e||new oe.Transaction;let r=[t.coin_type_a,t.coin_type_b],a=(0,I.asUintN)(BigInt(t.tick_lower)).toString(),u=(0,I.asUintN)(BigInt(t.tick_upper)).toString(),d=[e.object((0,I.getPackagerConfigs)(i).global_config_id),e.object(t.pool_id),e.pure.u32(Number(a)),e.pure.u32(Number(u))];return e.moveCall({target:`${n.published_at}::${Me}::open_position`,typeArguments:r,arguments:d}),e}async openPositionWithPricePayload(t,e){let{pool_id:i}=t,{clmm_pool:n,integrate:r}=this.sdk.sdkOptions;e=e||new oe.Transaction;let a=await this.sdk.Pool.getPool(i,!1),u=Number(a.tick_spacing),d=0,f=0;if(t.is_full_range)d=I.TickUtil.getMinIndex(u),f=I.TickUtil.getMaxIndex(u);else{let{price_base_coin:P,min_price:M,max_price:x}=t;d=I.TickMath.priceToInitializeTickIndex(P==="coin_a"?(0,I.d)(M):(0,I.d)(1).div(x),t.coin_decimals_a,t.coin_decimals_b,u),f=I.TickMath.priceToInitializeTickIndex(P==="coin_a"?(0,I.d)(x):(0,I.d)(1).div(M),t.coin_decimals_a,t.coin_decimals_b,u)}let h=[a.coin_type_a,a.coin_type_b],w=[e.object((0,I.getPackagerConfigs)(n).global_config_id),e.object(t.pool_id),e.pure.u32(Number((0,I.asUintN)(BigInt(d)))),e.pure.u32(Number((0,I.asUintN)(BigInt(f))))];return e.moveCall({target:`${r.published_at}::${Me}::open_position`,typeArguments:h,arguments:w}),e}async collectFeePayload(t,e,i,n){e=e||new oe.Transaction;let r=i||I.CoinAssist.buildCoinWithBalance(BigInt(0),t.coin_type_a,e),a=n||I.CoinAssist.buildCoinWithBalance(BigInt(0),t.coin_type_b,e);return this.createCollectFeePayload(t,e,r,a),e}createCollectFeePayload(t,e,i,n){let{clmm_pool:r,integrate:a}=this.sdk.sdkOptions,u=[t.coin_type_a,t.coin_type_b],d=[e.object((0,I.getPackagerConfigs)(r).global_config_id),e.object(t.pool_id),e.object(t.pos_id),i,n];return e.moveCall({target:`${a.published_at}::${Vt}::collect_fee`,typeArguments:u,arguments:d}),e}async calculateAddLiquidityResultWithPrice(t){let{pool_id:e,slippage:i,refresh_pool_price:n,add_mode_params:r}=t,a=await this.sdk.Pool.getPool(e,n),u=Number(a.tick_spacing),d=0,f=0;if(r.is_full_range)d=I.TickUtil.getMinIndex(u),f=I.TickUtil.getMaxIndex(u);else{let{price_base_coin:$,min_price:V,max_price:D}=r;d=I.TickMath.priceToInitializeTickIndex($==="coin_a"?(0,I.d)(V):(0,I.d)(1).div(D),r.coin_decimals_a,r.coin_decimals_b,u),f=I.TickMath.priceToInitializeTickIndex($==="coin_a"?(0,I.d)(D):(0,I.d)(1).div(V),r.coin_decimals_a,r.coin_decimals_b,u)}if("liquidity"in t){let{liquidity:$}=t,V=I.TickMath.tickIndexToSqrtPriceX64(d),D=I.TickMath.tickIndexToSqrtPriceX64(f),{coin_amount_a:W,coin_amount_b:Ht}=I.ClmmPoolUtil.getCoinAmountFromLiquidity(new $e.default($),new $e.default(a.current_sqrt_price),V,D,!1),et=(0,I.d)(W).mul(1+i).toFixed(0,O.ROUND_UP),zt=(0,I.d)(Ht).mul(1+i).toFixed(0,O.ROUND_UP);return{coin_amount_a:W,coin_amount_b:Ht,coin_amount_limit_a:et,coin_amount_limit_b:zt,liquidity:$,tick_lower:d,tick_upper:f}}let{coin_amount:h,fix_amount_a:w}=t,{coin_amount_limit_a:P,coin_amount_limit_b:M,liquidity_amount:x,coin_amount_a:S,coin_amount_b:z}=I.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(d,f,new $e.default(h),w,!0,i,new $e.default(a.current_sqrt_price));return{coin_amount_a:S,coin_amount_b:z,coin_amount_limit_a:P,coin_amount_limit_b:M,liquidity:x,tick_lower:d,tick_upper:f,fix_amount_a:w}}async addLiquidityWithPricePayload(t,e,i,n){let{pool_id:r,calculate_result:a}=t,{coin_amount_limit_a:u,coin_amount_limit_b:d,liquidity:f,tick_lower:h,tick_upper:w}=a;e=e||new oe.Transaction;let P=await this.sdk.Pool.getPool(r,!1);return await this.createAddLiquidityPayload({delta_liquidity:f,max_amount_a:u,max_amount_b:d,tick_lower:h,tick_upper:w,collect_fee:!1,rewarder_coin_types:[],coin_type_a:P.coin_type_a,coin_type_b:P.coin_type_b,pool_id:r,pos_id:""},e,i,n),e}async createAddLiquidityFixCoinWithPricePayload(t,e,i,n){let{pool_id:r,calculate_result:a}=t,{coin_amount_limit_a:u,coin_amount_limit_b:d,liquidity:f,tick_lower:h,tick_upper:w,fix_amount_a:P,coin_amount_a:M,coin_amount_b:x}=a;if(P===void 0)throw j("InvalidParams","fix_amount_a is undefined",{[I.DETAILS_KEYS.METHOD_NAME]:"addLiquidityFixCoinCoinWithPricePayload",[I.DETAILS_KEYS.REQUEST_PARAMS]:t});e=e||new oe.Transaction;let S=await this.sdk.Pool.getPool(r,!1);return await this.createAddLiquidityFixTokenPayload({amount_a:P?M:u,amount_b:P?d:x,slippage:0,fix_amount_a:P,is_open:!0,tick_lower:h,tick_upper:w,collect_fee:!1,rewarder_coin_types:[],coin_type_a:S.coin_type_a,coin_type_b:S.coin_type_b,pool_id:r,pos_id:""},void 0,e,i,n),e}createCollectFeeNoSendPayload(t,e,i,n){let{clmm_pool:r,integrate:a}=this.sdk.sdkOptions,u=[t.coin_type_a,t.coin_type_b],d=[e.object((0,I.getPackagerConfigs)(r).global_config_id),e.object(t.pool_id),e.object(t.pos_id),i,n];return e.moveCall({target:`${a.published_at}::${Re}::collect_fee`,typeArguments:u,arguments:d}),e}};var ui=require("@mysten/sui/transactions"),uo=require("@mysten/sui/utils"),en=ce(ee()),Y=require("@cetusprotocol/common-sdk");var Ke=class{constructor(t){this._sdk=t,this.growthGlobal=[Y.ZERO,Y.ZERO,Y.ZERO]}get sdk(){return this._sdk}async emissionsEveryDay(t){let i=(await this.sdk.Pool.getPool(t)).rewarder_infos;if(!i)return null;let n=[];for(let r of i){let a=Y.MathUtil.fromX64(new en.default(r.emissions_per_second));n.push({emissions:Math.floor(a.toNumber()*60*60*24),coin_type:r.coin_type})}return n}async batchFetchPositionRewarders(t){let e=[];for(let n of t){let r=await this._sdk.Position.getPositionById(n,!1),a=await this._sdk.Pool.getPool(r.pool,!1);e.push({pool_id:a.id,position_id:r.pos_object_id,coin_type_a:a.coin_type_a,coin_type_b:a.coin_type_b,rewarder_types:a.rewarder_infos.map(u=>u.coin_type)})}let i={};if(e.length>0){let n=await this.fetchPosRewardersAmount(e);for(let r of n)i[r.position_id]=r.rewarder_amounts;return i}return i}async fetchPositionRewarders(t,e){let i={pool_id:t.id,position_id:e,coin_type_a:t.coin_type_a,coin_type_b:t.coin_type_b,rewarder_types:t.rewarder_infos.map(r=>r.coin_type)};return(await this.fetchPosRewardersAmount([i]))[0].rewarder_amounts}async batchFetchPositionFees(t){return await this._sdk.Position.batchFetchPositionFees(t)}async fetchPosFeeAmount(t){return await this._sdk.Position.fetchPosFeeAmount(t)}buildFetchPosReward(t,e){let{clmm_pool:i,integrate:n}=this.sdk.sdkOptions,r=[t.coin_type_a,t.coin_type_b],a=[e.object((0,Y.getPackagerConfigs)(i).global_config_id),e.object(t.pool_id),e.pure.address(t.position_id),e.object(Y.CLOCK_ADDRESS)];e.moveCall({target:`${n.published_at}::${Qt}::fetch_position_rewards`,arguments:a,typeArguments:r})}async fetchPosRewardersAmount(t){let e=new ui.Transaction;for(let a of t)this.buildFetchPosReward(a,e);let i=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:e,sender:(0,uo.normalizeSuiAddress)("0x")});i.error!=null&&j("InvalidConfig",`fetch position rewards error code: ${i.error??"unknown error"}, please check config and params`,{[Y.DETAILS_KEYS.METHOD_NAME]:"fetchPosRewardersAmount",[Y.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}});let n=this.parsedPosRewardData(i),r=[];for(let a=0;a<t.length;a+=1){let u=n[t[a].position_id];if(u){let d={pool_id:t[a].pool_id,position_id:t[a].position_id,rewarder_amounts:u.rewarder_amount.map((f,h)=>({amount_owned:f,coin_type:t[a].rewarder_types[h]}))};r.push(d)}}return r}parsedPosRewardData(t){let e={},i=t.events?.filter(n=>n.type.includes("fetcher_script::FetchPositionRewardsEvent"));for(let n=0;n<i.length;n+=1){let{parsedJson:r}=i[n],a={position_id:r.position_id,rewarder_amount:r.data};e[r.position_id]=a}return e}async fetchPoolRewardersAmount(t,e){let i=await this.sdk.Pool.getPool(e),n=await this.sdk.Position.getPositionList(t,[e]),r=[];for(let d of n)r.push({pool_id:i.id,position_id:d.pos_object_id,rewarder_types:i.rewarder_infos.map(f=>f.coin_type),coin_type_a:i.coin_type_a,coin_type_b:i.coin_type_b});let a=await this.fetchPosRewardersAmount(r),u=[Y.ZERO,Y.ZERO,Y.ZERO];if(a!=null)for(let d of a)for(let f=0;f<d.rewarder_amounts.length;f+=1)u[f]=u[f].add(new en.default(d.rewarder_amounts[f].amount_owned));return u}async getPoolLowerAndUpperTicks(t,e){let i=[],n=[];for(let r of e){let a=await this.sdk.Pool.getTickDataByIndex(t,r.tick_lower_index),u=await this.sdk.Pool.getTickDataByIndex(t,r.tick_upper_index);i.push(a),n.push(u)}return[i,n]}async collectRewarderPayload(t){let e=await this.sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress(),null),i=new ui.Transaction;return i=Zt.createCollectRewarderAndFeeParams(this._sdk,i,t,e),i}async batchCollectRewardsPayload(t,e,i,n){let r=await this.sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress(),null);e=e||new ui.Transaction;let a={};return t.forEach(u=>{let d=(0,Y.normalizeCoinType)(u.coin_type_a),f=(0,Y.normalizeCoinType)(u.coin_type_b);if(u.collect_fee){let w=a[d];w==null&&(i==null?w=Y.CoinAssist.buildCoinForAmount(e,r,BigInt(0),d,!1):w={target_coin:i,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},a[d]=w);let P=a[f];P==null&&(n==null?P=Y.CoinAssist.buildCoinForAmount(e,r,BigInt(0),f,!1):P={target_coin:n,remain_coins:[],is_mint_zero_coin:!1,target_coin_amount:"0",selected_coins:[]},a[f]=P),e=this._sdk.Position.createCollectFeeNoSendPayload({pool_id:u.pool_id,pos_id:u.pos_id,coin_type_a:u.coin_type_a,coin_type_b:u.coin_type_b},e,w.target_coin,P.target_coin)}let h=[];u.rewarder_coin_types.forEach(w=>{let P=(0,Y.normalizeCoinType)(w),M=a[w];M===void 0&&(M=Y.CoinAssist.buildCoinForAmount(e,r,BigInt(0),P,!1),a[P]=M),h.push(M.target_coin)}),e=this.createCollectRewarderNoSendPayload(u,e,h)}),Object.keys(a).forEach(u=>{let d=a[u];d.is_mint_zero_coin&&tn(this.sdk,e,d.target_coin,u,this.sdk.getSenderAddress())}),e}createCollectRewarderPayload(t,e,i){let{clmm_pool:n,integrate:r}=this.sdk.sdkOptions,a=(0,Y.getPackagerConfigs)(n),u=[t.coin_type_a,t.coin_type_b];return t.rewarder_coin_types.forEach((d,f)=>{e&&e.moveCall({target:`${r.published_at}::${Vt}::collect_reward`,typeArguments:[...u,d],arguments:[e.object(a.global_config_id),e.object(t.pool_id),e.object(t.pos_id),e.object(a.global_vault_id),i[f],e.object(Y.CLOCK_ADDRESS)]})}),e}createCollectRewarderNoSendPayload(t,e,i){let{clmm_pool:n,integrate:r}=this.sdk.sdkOptions,a=(0,Y.getPackagerConfigs)(n),u=[t.coin_type_a,t.coin_type_b];return t.rewarder_coin_types.forEach((d,f)=>{e&&e.moveCall({target:`${r.published_at}::${Re}::collect_reward`,typeArguments:[...u,d],arguments:[e.object(a.global_config_id),e.object(t.pool_id),e.object(t.pos_id),e.object(a.global_vault_id),i[f],e.object(Y.CLOCK_ADDRESS)]})}),e}};var nn=require("@mysten/sui/transactions"),on=require("@mysten/sui/utils"),we=ce(ee()),nt=require("@cetusprotocol/common-sdk");var $r="amm_swap",Ur="Pool",We=class{constructor(t){this.calculateSingleImpact=(t,e)=>e.minus(t).div(e).mul(100);this._sdk=t}get sdk(){return this._sdk}calculateSwapFee(t){let e=(0,nt.d)(0);return t.forEach(i=>{let n=i.base_paths.length;if(n>0){let r=i.base_paths[0],a=r.label==="Cetus"?new O(r.fee_rate).div(10**6):new O(r.fee_rate).div(10**9),u=(0,nt.d)(r.input_amount).div(10**r.from_decimal).mul(a);if(e=e.add(u),n>1){let d=i.base_paths[1],f=r.direction?r.current_price:new O(1).div(r.current_price),h=d.direction?d.current_price:new O(1).div(d.current_price),w=d.label==="Cetus"?new O(d.fee_rate).div(10**6):new O(d.fee_rate).div(10**9),M=(0,nt.d)(d.output_amount).div(10**d.to_decimal).mul(w).div(f.mul(h));e=e.add(M)}}}),e.toString()}calculateSwapPriceImpact(t){let e=(0,nt.d)(0);return t.forEach(i=>{let n=i.base_paths.length;if(n===1){let r=i.base_paths[0],a=(0,nt.d)(r.output_amount).div(10**r.to_decimal),u=(0,nt.d)(r.input_amount).div(10**r.from_decimal),d=a.div(u),f=r.direction?new O(r.current_price):new O(1).div(r.current_price);e=e.add(this.calculateSingleImpact(d,f))}if(n===2){let r=i.base_paths[0],a=i.base_paths[1],u=r.direction?new O(r.current_price):new O(1).div(r.current_price),d=a.direction?new O(a.current_price):new O(1).div(a.current_price),f=u.mul(d),h=new O(a.output_amount).div(10**a.to_decimal),w=new O(r.input_amount).div(10**r.from_decimal),P=h.div(w);e=e.add(this.calculateSingleImpact(P,f))}}),e.toString()}async preSwapWithMultiPool(t){let{integrate:e}=this.sdk.sdkOptions,i=new nn.Transaction,n=[t.coin_type_a,t.coin_type_b];for(let f=0;f<t.pool_ids.length;f+=1){let h=[i.object(t.pool_ids[f]),i.pure.bool(t.a2b),i.pure.bool(t.by_amount_in),i.pure.u64(t.amount)];i.moveCall({target:`${e.published_at}::${Qt}::calculate_swap_result`,arguments:h,typeArguments:n})}let r=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:i,sender:(0,on.normalizeSuiAddress)("0x0")});r.error!=null&&j("InvalidConfig",`pre swap with multi pools error code: ${r.error??"unknown error"}, please check config and params`,{[nt.DETAILS_KEYS.METHOD_NAME]:"preSwapWithMultiPool",[nt.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}});let a=r.events?.filter(f=>(0,nt.extractStructTagFromType)(f.type).name==="CalculatedSwapResultEvent");if(a.length===0)return null;a.length!==t.pool_ids.length&&j("ParamsLengthNotEqual","valueData.length !== params.pools.length",{[nt.DETAILS_KEYS.METHOD_NAME]:"preSwapWithMultiPool",[nt.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}});let u=t.by_amount_in?nt.ZERO:nt.U64_MAX,d=0;for(let f=0;f<a.length;f+=1)if(!a[f].parsedJson.data.is_exceed)if(t.by_amount_in){let h=new we.default(a[f].parsedJson.data.amount_out);h.gt(u)&&(d=f,u=h)}else{let h=new we.default(a[f].parsedJson.data.amount_out);h.lt(u)&&(d=f,u=h)}return this.transformSwapWithMultiPoolData({pool_address:t.pool_ids[d],a2b:t.a2b,by_amount_in:t.by_amount_in,amount:t.amount,coin_type_a:t.coin_type_a,coin_type_b:t.coin_type_b},a[d].parsedJson)}async preSwap(t){let{integrate:e}=this.sdk.sdkOptions,i=new nn.Transaction,n=[t.coin_type_a,t.coin_type_b],r=[i.object(t.pool.id),i.pure.bool(t.a2b),i.pure.bool(t.by_amount_in),i.pure.u64(t.amount)];i.moveCall({target:`${e.published_at}::${Qt}::calculate_swap_result`,arguments:r,typeArguments:n});let a=await this.sdk.FullClient.devInspectTransactionBlock({transactionBlock:i,sender:(0,on.normalizeSuiAddress)("0x0")});if(a.error!=null)return j("InvalidConfig",`preSwap error code: ${a.error??"unknown error"}, please check config and params`,{[nt.DETAILS_KEYS.METHOD_NAME]:"preSwap",[nt.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}});let u=a.events?.filter(d=>(0,nt.extractStructTagFromType)(d.type).name==="CalculatedSwapResultEvent");return u.length===0?j("InvalidConfig",`preSwap error code: ${a.error??"unknown error"}, please check config and params`,{[nt.DETAILS_KEYS.METHOD_NAME]:"preSwap",[nt.DETAILS_KEYS.REQUEST_PARAMS]:{params:t}}):this.transformSwapData(t,u[0].parsedJson.data)}transformSwapData(t,e){let i=e.amount_in&&e.fee_amount?new we.default(e.amount_in).add(new we.default(e.fee_amount)).toString():"";return{pool_address:t.pool.id,current_sqrt_price:t.current_sqrt_price,estimated_amount_in:i,estimated_amount_out:e.amount_out,estimated_end_sqrt_price:e.after_sqrt_price,estimated_fee_amount:e.fee_amount,is_exceed:e.is_exceed,amount:t.amount,a2b:t.a2b,by_amount_in:t.by_amount_in}}transformSwapWithMultiPoolData(t,e){let{data:i}=e;console.log("json data. ",i);let n=i.amount_in&&i.fee_amount?new we.default(i.amount_in).add(new we.default(i.fee_amount)).toString():"";return{pool_address:t.pool_address,estimated_amount_in:n,estimated_amount_out:i.amount_out,estimated_end_sqrt_price:i.after_sqrt_price,estimated_start_sqrt_price:i.step_results[0].current_sqrt_price,estimated_fee_amount:i.fee_amount,is_exceed:i.is_exceed,amount:t.amount,a2b:t.a2b,by_amount_in:t.by_amount_in}}calculateRates(t){let{current_pool:e}=t,i=Vi(e),n;t.a2b?n=t.swap_ticks.sort((P,M)=>M.index-P.index):n=t.swap_ticks.sort((P,M)=>P.index-M.index);let r=Qi(t.a2b,t.by_amount_in,t.amount,i,n),a=!1;t.by_amount_in?a=r.amount_in.lt(t.amount):a=r.amount_out.lt(t.amount);let u=Xt.getDefaultSqrtPriceLimit(t.a2b);t.a2b&&r.next_sqrt_price.lt(u)&&(a=!0),!t.a2b&&r.next_sqrt_price.gt(u)&&(a=!0);let d=0;r.cross_tick_num>6&&r.cross_tick_num<40&&(d=22e3*(r.cross_tick_num-6)),r.cross_tick_num>40&&(a=!0);let f=nt.TickMath.sqrtPriceX64ToPrice(i.current_sqrt_price,t.decimals_a,t.decimals_b).toNumber(),h=nt.TickMath.sqrtPriceX64ToPrice(r.next_sqrt_price,t.decimals_a,t.decimals_b).toNumber(),w=Math.abs(f-h)/f*100;return{estimated_amount_in:r.amount_in,estimated_amount_out:r.amount_out,estimated_end_sqrt_price:r.next_sqrt_price,estimated_fee_amount:r.fee_amount,is_exceed:a,extra_compute_limit:d,amount:t.amount,a2b:t.a2b,by_amount_in:t.by_amount_in,price_impact_pct:w}}async createSwapPayload(t,e){let i=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());if(e){let{is_adjust_coin_a:n,is_adjust_coin_b:r}=ge(t);if(t.a2b&&n||!t.a2b&&r)return await Xt.buildSwapTransactionForGas(this._sdk,t,i,e)}return Xt.buildSwapTransaction(this.sdk,t,i)}async createSwapWithoutTransferCoinsPayload(t,e){let i=await this._sdk.FullClient.getOwnerCoinAssets(this.sdk.getSenderAddress());if(e){let{is_adjust_coin_a:n,is_adjust_coin_b:r}=ge(t);if(t.a2b&&n||!t.a2b&&r)return await Xt.buildSwapTransactionWithoutTransferCoinsForGas(this._sdk,t,i,e)}return Xt.buildSwapTransactionWithoutTransferCoins(this.sdk,t,i)}};var _o=require("@cetusprotocol/common-sdk"),fo={clmmConfig:{pools_id:"0xf699e7f2276f5c9a75944b37a0c5b5d9ddfd2471bf6242483b03ab2887d198d0",global_config_id:"0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",global_vault_id:"0xce7bceef26d3ad1f6d9b6f13a953f053e6ed3ca77907516481ce99ae8e588f2b",admin_cap_id:"0x89c1a321291d15ddae5a086c9abc533dff697fde3d89e0ca836c41af73e36a75"},cetusConfig:{coin_list_id:"0x8cbc11d9e10140db3d230f50b4d30e9b721201c0083615441707ffec1ef77b23",launchpad_pools_id:"0x1098fac992eab3a0ab7acf15bb654fc1cf29b5a6142c4ef1058e6c408dd15115",clmm_pools_id:"0x15b6a27dd9ae03eb455aba03b39e29aad74abd3757b8e18c0755651b2ae5b71e",admin_cap_id:"0x39d78781750e193ce35c45ff32c6c0c3f2941fa3ddaf8595c90c555589ddb113",global_config_id:"0x0408fa4e4a4c03cc0de8f23d0c2bbfe8913d178713c9a271ed4080973fe42d8f",coin_list_handle:"0x49136005e90e28c4695419ed4194cc240603f1ea8eb84e62275eaff088a71063",launchpad_pools_handle:"0x5e194a8efcf653830daf85a85b52e3ae8f65dc39481d54b2382acda25068375c",clmm_pools_handle:"0x37f60eb2d9d227949b95da8fea810db3c32d1e1fa8ed87434fc51664f87d83cb"}},rn={env:"mainnet",full_rpc_url:_o.FullRpcUrlMainnet,cetus_config:{package_id:"0x95b8d278b876cae22206131fb9724f701c9444515813042f54f0a426c9a3bc2f",published_at:"0x95b8d278b876cae22206131fb9724f701c9444515813042f54f0a426c9a3bc2f",config:fo.cetusConfig},clmm_pool:{package_id:"0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb",published_at:"0xc6faf3703b0e8ba9ed06b7851134bbbe7565eb35ff823fd78432baa4cbeaa12e",config:fo.clmmConfig},integrate:{package_id:"0x996c4d9480708fb8b92aa7acf819fb0497b5ec8e65ba06601cae2fb6db3312c3",published_at:"0x2d8c2e0fc6dd25b0214b3fa747e0fd27fd54608142cd2e4f64c1cd350cc4add4"},stats_pools_url:"https://api-sui.cetus.zone/v2/sui/stats_pools"};var po=require("@cetusprotocol/common-sdk"),ho={clmmConfig:{pools_id:"0x50eb61dd5928cec5ea04711a2e9b72e5237e79e9fbcd2ce3d5469dc8708e0ee2",global_config_id:"0x9774e359588ead122af1c7e7f64e14ade261cfeecdb5d0eb4a5b3b4c8ab8bd3e",global_vault_id:"0xf78d2ee3c312f298882cb680695e5e8c81b1d441a646caccc058006c2851ddea",admin_cap_id:"0xa456f86a53fc31e1243f065738ff1fc93f5a62cc080ff894a0fb3747556a799b"},cetusConfig:{coin_list_id:"0x257eb2ba592a5480bba0a97d05338fab17cc3283f8df6998a0e12e4ab9b84478",launchpad_pools_id:"0xdc3a7bd66a6dcff73c77c866e87d73826e446e9171f34e1c1b656377314f94da",clmm_pools_id:"0x26c85500f5dd2983bf35123918a144de24e18936d0b234ef2b49fbb2d3d6307d",admin_cap_id:"0x1a496f6c67668eb2c27c99e07e1d61754715c1acf86dac45020c886ac601edb8",global_config_id:"0xe1f3db327e75f7ec30585fa52241edf66f7e359ef550b533f89aa1528dd1be52",coin_list_handle:"0x3204350fc603609c91675e07b8f9ac0999b9607d83845086321fca7f469de235",launchpad_pools_handle:"0xae67ff87c34aceea4d28107f9c6c62e297a111e9f8e70b9abbc2f4c9f5ec20fd",clmm_pools_handle:"0xd28736923703342b4752f5ed8c2f2a5c0cb2336c30e1fed42b387234ce8408ec"}},sn={env:"testnet",full_rpc_url:po.FullRpcUrlTestnet,cetus_config:{package_id:"0xf5ff7d5ba73b581bca6b4b9fa0049cd320360abd154b809f8700a8fd3cfaf7ca",published_at:"0xf5ff7d5ba73b581bca6b4b9fa0049cd320360abd154b809f8700a8fd3cfaf7ca",config:ho.cetusConfig},clmm_pool:{package_id:"0x0c7ae833c220aa73a3643a0d508afa4ac5d50d97312ea4584e35f9eb21b9df12",published_at:"0x85e61285a10efc6602ab00df70a0c06357c384ef4c5633ecf73016df1500c704",config:ho.clmmConfig},integrate:{package_id:"0x2918cf39850de6d5d94d8196dc878c8c722cd79db659318e00bff57fbb4e2ede",published_at:"0x19dd42e05fa6c9988a60d30686ee3feb776672b5547e328d6dab16563da65293"},stats_pools_url:"https://api-sui.devcetus.com/v2/sui/stats_pools"};var He=class o extends mo.SdkWrapper{constructor(t){super(t),this._swap=new We(this),this._pool=new Le(this),this._position=new Ue(this),this._config=new Ie(this),this._rewarder=new Ke(this)}get Pool(){return this._pool}get Position(){return this._position}get CetusConfig(){return this._config}get Rewarder(){return this._rewarder}get Swap(){return this._swap}static createSDK(t){let{env:e="mainnet"}=t;return e==="mainnet"?o.createCustomSDK({...rn,...t}):o.createCustomSDK({...sn,...t})}static createCustomSDK(t){return new o(t)}};var Ze=ce(ee()),re=require("@cetusprotocol/common-sdk");var Kr=new Ze.default(365),Wr=new Ze.default(24),Hr=new Ze.default(3600),Zr=new Ze.default(.5);function zr(o,t,e,i){return Kr.mul(Wr).mul(Hr).mul(Zr).mul(o.mul(t).add(e).div(i))}function Gr(o,t,e,i,n,r){let a=new O(o.toString()).div(new O(10**e)),u=new O(t.toString()).div(new O(10**i));return a.mul(n).add(u.mul(r))}function Vr(o,t,e,i,n,r,a,u,d,f,h,w,P,M,x,S,z,$,V,D,W,Ht,et,zt){let se=new O(w),Yt=new O(P),ae=new O(S),Z=new O(z),Kt=new O($),y=new O(V),s=new O(D),l=new O(W),_=new O(Ht),p=new O(et),g=new O(zt),v=re.TickMath.tickIndexToSqrtPriceX64(t),C=re.TickMath.tickIndexToSqrtPriceX64(e),m=re.MathUtil.toX64Decimal(re.MathUtil.fromX64(v)).round(),c=re.MathUtil.toX64Decimal(re.MathUtil.fromX64(C)).round(),b=re.MathUtil.toX64Decimal(re.MathUtil.fromX64(i)).round(),T,R=se.mul(new O(10**r)).mul(c.mul(m)).div(c.sub(m)).round(),F=Yt.mul(new O(10**a)).div(c.sub(m)).round();o<t?T=R:o>e?T=F:T=O.min(R,F);let U=T.mul(b.sub(m)),Q=T.mul(c.sub(b)).div(b.mul(c)).div(new O(10**r)).mul(s).add(U.div(new O(10**a).mul(l))),te=Gr(M,x,r,a,s,l),J=Q.div(te),it=T.eq(new O(0))?new O(0):new O(h/1e4).mul(ae).mul(new O(T.toString()).div(new O(n.toString()).add(new O(T.toString())))).div(Q),ye=J.eq(new O(0))?new O(0):J.mul(new O(36500/7)).div(Q),ot=Z.div(new O(10**u)).mul(_).mul(ye),rt=Kt.div(new O(10**d)).mul(p).mul(ye),ze=y.div(new O(10**f)).mul(g).mul(ye);return{fee_apr:it,pos_rewarder_0_apr:ot,pos_rewarder_1_apr:rt,pos_rewarder_2_apr:ze}}function Qr(o,t,e,i){let n=Math.max(o,e),a=Math.min(t,i)-n,u=t-o,d=i-e,f=new O(u.toString()),h=new O(d.toString()),w=new O(a.toString()),P=new O("0");return a<0?P=new O("0"):u===a?P=h.div(w):d===a?P=w.div(f):P=w.mul(w).div(h).div(f),P}var Jr=He;0&&(module.exports={AMM_SWAP_MODULE,CetusClmmSDK,ClmmError,ClmmExpectSwapModule,ClmmFetcherModule,ClmmIntegratePoolModule,ClmmIntegratePoolV2Module,ClmmIntegratePoolV3Module,ClmmIntegrateRouterModule,ClmmIntegrateRouterWithPartnerModule,ClmmIntegrateUtilsModule,ClmmPartnerModule,ClmmPositionStatus,ConfigErrorCode,ConfigModule,DeepbookClobV2Module,DeepbookCustodianV2Module,DeepbookEndpointsV2Module,POOL_STRUCT,PartnerErrorCode,PoolErrorCode,PoolModule,PositionErrorCode,PositionModule,PositionUtils,RewarderModule,RouterErrorCode,SwapErrorCode,SwapModule,SwapUtils,TypesErrorCode,UtilsErrorCode,buildClmmPositionName,buildPool,buildPoolTransactionInfo,buildPosition,buildPositionReward,buildPositionTransactionInfo,buildTickData,buildTickDataByEvent,buildTransferCoin,buildTransferCoinToSender,clmmMainnet,clmmTestnet,computeSwap,computeSwapStep,estPoolAPR,estPositionAPRWithDeltaMethod,estPositionAPRWithMultiMethod,findAdjustCoin,getDefaultSuiInputType,getLowerSqrtPriceFromCoinA,getLowerSqrtPriceFromCoinB,getUpperSqrtPriceFromCoinA,getUpperSqrtPriceFromCoinB,handleError,handleMessageError,newBits,poolFilterEvenTypes,transClmmpoolDataWithoutTicks});
2
+ /*! Bundled license information:
3
+
4
+ decimal.js/decimal.mjs:
5
+ (*!
6
+ * decimal.js v10.5.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