@raydium-io/raydium-sdk-v2 0.2.1-alpha → 0.2.2-alpha

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 (101) hide show
  1. package/lib/api/api.d.ts +1 -1
  2. package/lib/api/index.d.ts +1 -1
  3. package/lib/api/index.js.map +1 -1
  4. package/lib/api/index.mjs.map +1 -1
  5. package/lib/api/type.d.ts +1 -1
  6. package/lib/api/type.js +1 -1
  7. package/lib/api/type.js.map +1 -1
  8. package/lib/api/type.mjs.map +1 -1
  9. package/lib/{api-24bf4058.d.ts → api-0017263f.d.ts} +5 -0
  10. package/lib/common/accountInfo.d.ts +1 -1
  11. package/lib/common/bignumber.d.ts +1 -1
  12. package/lib/common/constant.d.ts +1 -1
  13. package/lib/common/fractionUtil.d.ts +1 -1
  14. package/lib/common/index.d.ts +1 -1
  15. package/lib/common/transfer.d.ts +1 -1
  16. package/lib/common/txTool/txTool.d.ts +1 -1
  17. package/lib/common/txTool/txUtils.d.ts +1 -1
  18. package/lib/common/utility.d.ts +1 -1
  19. package/lib/index.d.ts +3 -3
  20. package/lib/index.js.map +1 -1
  21. package/lib/index.mjs.map +1 -1
  22. package/lib/module/amount.d.ts +1 -1
  23. package/lib/module/fraction.d.ts +1 -1
  24. package/lib/module/index.d.ts +1 -1
  25. package/lib/module/percent.d.ts +1 -1
  26. package/lib/module/price.d.ts +1 -1
  27. package/lib/raydium/account/account.d.ts +3 -3
  28. package/lib/raydium/account/index.d.ts +1 -1
  29. package/lib/raydium/account/instruction.d.ts +1 -1
  30. package/lib/raydium/account/types.d.ts +1 -1
  31. package/lib/raydium/account/util.d.ts +1 -1
  32. package/lib/raydium/clmm/clmm.d.ts +3 -3
  33. package/lib/raydium/clmm/index.d.ts +3 -3
  34. package/lib/raydium/clmm/index.js +1 -1
  35. package/lib/raydium/clmm/index.mjs +1 -1
  36. package/lib/raydium/clmm/instrument.d.ts +2 -2
  37. package/lib/raydium/clmm/type.d.ts +2 -2
  38. package/lib/raydium/clmm/utils/math.d.ts +2 -2
  39. package/lib/raydium/clmm/utils/pool.d.ts +2 -2
  40. package/lib/raydium/clmm/utils/position.d.ts +2 -2
  41. package/lib/raydium/clmm/utils/tick.d.ts +2 -2
  42. package/lib/raydium/clmm/utils/tickQuery.d.ts +2 -2
  43. package/lib/raydium/clmm/utils/tickarrayBitmap.d.ts +2 -2
  44. package/lib/raydium/cpmm/cpmm.d.ts +3 -3
  45. package/lib/raydium/cpmm/curve/calculator.d.ts +1 -1
  46. package/lib/raydium/cpmm/curve/constantProduct.d.ts +1 -1
  47. package/lib/raydium/cpmm/index.d.ts +1 -1
  48. package/lib/raydium/cpmm/instruction.d.ts +1 -1
  49. package/lib/raydium/cpmm/type.d.ts +1 -1
  50. package/lib/raydium/farm/config.d.ts +1 -1
  51. package/lib/raydium/farm/farm.d.ts +3 -3
  52. package/lib/raydium/farm/index.d.ts +1 -1
  53. package/lib/raydium/farm/instruction.d.ts +1 -1
  54. package/lib/raydium/farm/layout.d.ts +1 -1
  55. package/lib/raydium/farm/type.d.ts +1 -1
  56. package/lib/raydium/farm/util.d.ts +1 -1
  57. package/lib/raydium/ido/ido.d.ts +3 -3
  58. package/lib/raydium/ido/index.d.ts +3 -3
  59. package/lib/raydium/ido/instruction.d.ts +1 -1
  60. package/lib/raydium/ido/type.d.ts +1 -1
  61. package/lib/raydium/index.d.ts +3 -3
  62. package/lib/raydium/launchpad/curve/constantProductCurve.d.ts +1 -1
  63. package/lib/raydium/launchpad/curve/curve.d.ts +1 -1
  64. package/lib/raydium/launchpad/curve/curve.js +1 -1
  65. package/lib/raydium/launchpad/curve/curve.mjs +1 -1
  66. package/lib/raydium/launchpad/curve/curveBase.d.ts +1 -1
  67. package/lib/raydium/launchpad/curve/fixedPriceCurve.d.ts +1 -1
  68. package/lib/raydium/launchpad/curve/linearPriceCurve.d.ts +1 -1
  69. package/lib/raydium/launchpad/curve/linearPriceCurve.js +1 -1
  70. package/lib/raydium/launchpad/curve/linearPriceCurve.js.map +1 -1
  71. package/lib/raydium/launchpad/curve/linearPriceCurve.mjs +1 -1
  72. package/lib/raydium/launchpad/curve/linearPriceCurve.mjs.map +1 -1
  73. package/lib/raydium/launchpad/index.d.ts +3 -3
  74. package/lib/raydium/launchpad/launchpad.d.ts +3 -3
  75. package/lib/raydium/launchpad/pda.d.ts +1 -1
  76. package/lib/raydium/launchpad/type.d.ts +1 -1
  77. package/lib/raydium/liquidity/index.d.ts +1 -1
  78. package/lib/raydium/liquidity/instruction.d.ts +1 -1
  79. package/lib/raydium/liquidity/liquidity.d.ts +3 -3
  80. package/lib/raydium/liquidity/type.d.ts +1 -1
  81. package/lib/raydium/liquidity/utils.d.ts +1 -1
  82. package/lib/raydium/marketV2/createMarket.d.ts +3 -3
  83. package/lib/raydium/marketV2/index.d.ts +3 -3
  84. package/lib/raydium/moduleBase.d.ts +3 -3
  85. package/lib/raydium/raydium.d.ts +3 -3
  86. package/lib/raydium/token/constant.d.ts +1 -1
  87. package/lib/raydium/token/index.d.ts +1 -1
  88. package/lib/raydium/token/token.d.ts +3 -3
  89. package/lib/raydium/token/type.d.ts +1 -1
  90. package/lib/raydium/token/utils.d.ts +1 -1
  91. package/lib/raydium/tradeV2/index.d.ts +2 -2
  92. package/lib/raydium/tradeV2/instrument.d.ts +2 -2
  93. package/lib/raydium/tradeV2/trade.d.ts +3 -3
  94. package/lib/raydium/tradeV2/type.d.ts +2 -2
  95. package/lib/raydium/type.d.ts +1 -1
  96. package/lib/raydium/utils1216/index.d.ts +3 -3
  97. package/lib/raydium/utils1216/utils1216.d.ts +3 -3
  98. package/lib/{raydium-80c3ce5d.d.ts → raydium-2d36f2ed.d.ts} +2 -2
  99. package/lib/{type-a20a0a77.d.ts → type-afa99d0e.d.ts} +1 -1
  100. package/package.json +1 -1
  101. package/src/api/type.ts +5 -0
@@ -1,2 +1,2 @@
1
- var Mn=Object.defineProperty,Fn=Object.defineProperties;var On=Object.getOwnPropertyDescriptors;var Mt=Object.getOwnPropertySymbols;var En=Object.prototype.hasOwnProperty,vn=Object.prototype.propertyIsEnumerable;var Ft=(t,e,n)=>e in t?Mn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,H=(t,e)=>{for(var n in e||(e={}))En.call(e,n)&&Ft(t,n,e[n]);if(Mt)for(var n of Mt(e))vn.call(e,n)&&Ft(t,n,e[n]);return t},j=(t,e)=>Fn(t,On(e));import re from"bn.js";import Me from"bn.js";var ge=9e15,le=1e9,st="0123456789abcdef",_e="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Ve="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",at={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-ge,maxE:ge,crypto:!1},Dt,oe,T=!0,qe="[DecimalError] ",ce=qe+"Invalid argument: ",_t=qe+"Precision limit exceeded",Vt=qe+"crypto unavailable",Wt="[object Decimal]",V=Math.floor,E=Math.pow,Dn=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,_n=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Vn=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,qt=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,$=1e7,A=7,Wn=9007199254740991,qn=_e.length-1,ut=Ve.length-1,p={toStringTag:Wt};p.absoluteValue=p.abs=function(){var t=new this.constructor(this);return t.s<0&&(t.s=1),g(t)};p.ceil=function(){return g(new this.constructor(this),this.e+1,2)};p.clampedTo=p.clamp=function(t,e){var n,i=this,r=i.constructor;if(t=new r(t),e=new r(e),!t.s||!e.s)return new r(NaN);if(t.gt(e))throw Error(ce+e);return n=i.cmp(t),n<0?t:i.cmp(e)>0?e:new r(i)};p.comparedTo=p.cmp=function(t){var e,n,i,r,o=this,s=o.d,a=(t=new o.constructor(t)).d,c=o.s,u=t.s;if(!s||!a)return!c||!u?NaN:c!==u?c:s===a?0:!s^c<0?1:-1;if(!s[0]||!a[0])return s[0]?c:a[0]?-u:0;if(c!==u)return c;if(o.e!==t.e)return o.e>t.e^c<0?1:-1;for(i=s.length,r=a.length,e=0,n=i<r?i:r;e<n;++e)if(s[e]!==a[e])return s[e]>a[e]^c<0?1:-1;return i===r?0:i>r^c<0?1:-1};p.cosine=p.cos=function(){var t,e,n=this,i=n.constructor;return n.d?n.d[0]?(t=i.precision,e=i.rounding,i.precision=t+Math.max(n.e,n.sd())+A,i.rounding=1,n=Gn(i,Zt(i,n)),i.precision=t,i.rounding=e,g(oe==2||oe==3?n.neg():n,t,e,!0)):new i(1):new i(NaN)};p.cubeRoot=p.cbrt=function(){var t,e,n,i,r,o,s,a,c,u,l=this,m=l.constructor;if(!l.isFinite()||l.isZero())return new m(l);for(T=!1,o=l.s*E(l.s*l,1/3),!o||Math.abs(o)==1/0?(n=D(l.d),t=l.e,(o=(t-n.length+1)%3)&&(n+=o==1||o==-2?"0":"00"),o=E(n,1/3),t=V((t+1)/3)-(t%3==(t<0?-1:2)),o==1/0?n="5e"+t:(n=o.toExponential(),n=n.slice(0,n.indexOf("e")+1)+t),i=new m(n),i.s=l.s):i=new m(o.toString()),s=(t=m.precision)+3;;)if(a=i,c=a.times(a).times(a),u=c.plus(l),i=C(u.plus(l).times(a),u.plus(c),s+2,1),D(a.d).slice(0,s)===(n=D(i.d)).slice(0,s))if(n=n.slice(s-3,s+1),n=="9999"||!r&&n=="4999"){if(!r&&(g(a,t+1,0),a.times(a).times(a).eq(l))){i=a;break}s+=4,r=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(g(i,t+1,1),e=!i.times(i).times(i).eq(l));break}return T=!0,g(i,t,m.rounding,e)};p.decimalPlaces=p.dp=function(){var t,e=this.d,n=NaN;if(e){if(t=e.length-1,n=(t-V(this.e/A))*A,t=e[t],t)for(;t%10==0;t/=10)n--;n<0&&(n=0)}return n};p.dividedBy=p.div=function(t){return C(this,new this.constructor(t))};p.dividedToIntegerBy=p.divToInt=function(t){var e=this,n=e.constructor;return g(C(e,new n(t),0,1,1),n.precision,n.rounding)};p.equals=p.eq=function(t){return this.cmp(t)===0};p.floor=function(){return g(new this.constructor(this),this.e+1,3)};p.greaterThan=p.gt=function(t){return this.cmp(t)>0};p.greaterThanOrEqualTo=p.gte=function(t){var e=this.cmp(t);return e==1||e===0};p.hyperbolicCosine=p.cosh=function(){var t,e,n,i,r,o=this,s=o.constructor,a=new s(1);if(!o.isFinite())return new s(o.s?1/0:NaN);if(o.isZero())return a;n=s.precision,i=s.rounding,s.precision=n+Math.max(o.e,o.sd())+4,s.rounding=1,r=o.d.length,r<32?(t=Math.ceil(r/3),e=(1/Ue(4,t)).toString()):(t=16,e="2.3283064365386962890625e-10"),o=ye(s,1,o.times(e),new s(1),!0);for(var c,u=t,l=new s(8);u--;)c=o.times(o),o=a.minus(c.times(l.minus(c.times(l))));return g(o,s.precision=n,s.rounding=i,!0)};p.hyperbolicSine=p.sinh=function(){var t,e,n,i,r=this,o=r.constructor;if(!r.isFinite()||r.isZero())return new o(r);if(e=o.precision,n=o.rounding,o.precision=e+Math.max(r.e,r.sd())+4,o.rounding=1,i=r.d.length,i<3)r=ye(o,2,r,r,!0);else{t=1.4*Math.sqrt(i),t=t>16?16:t|0,r=r.times(1/Ue(5,t)),r=ye(o,2,r,r,!0);for(var s,a=new o(5),c=new o(16),u=new o(20);t--;)s=r.times(r),r=r.times(a.plus(s.times(c.times(s).plus(u))))}return o.precision=e,o.rounding=n,g(r,e,n,!0)};p.hyperbolicTangent=p.tanh=function(){var t,e,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(t=i.precision,e=i.rounding,i.precision=t+7,i.rounding=1,C(n.sinh(),n.cosh(),i.precision=t,i.rounding=e)):new i(n.s)};p.inverseCosine=p.acos=function(){var t,e=this,n=e.constructor,i=e.abs().cmp(1),r=n.precision,o=n.rounding;return i!==-1?i===0?e.isNeg()?J(n,r,o):new n(0):new n(NaN):e.isZero()?J(n,r+4,o).times(.5):(n.precision=r+6,n.rounding=1,e=e.asin(),t=J(n,r+4,o).times(.5),n.precision=r,n.rounding=o,t.minus(e))};p.inverseHyperbolicCosine=p.acosh=function(){var t,e,n=this,i=n.constructor;return n.lte(1)?new i(n.eq(1)?0:NaN):n.isFinite()?(t=i.precision,e=i.rounding,i.precision=t+Math.max(Math.abs(n.e),n.sd())+4,i.rounding=1,T=!1,n=n.times(n).minus(1).sqrt().plus(n),T=!0,i.precision=t,i.rounding=e,n.ln()):new i(n)};p.inverseHyperbolicSine=p.asinh=function(){var t,e,n=this,i=n.constructor;return!n.isFinite()||n.isZero()?new i(n):(t=i.precision,e=i.rounding,i.precision=t+2*Math.max(Math.abs(n.e),n.sd())+6,i.rounding=1,T=!1,n=n.times(n).plus(1).sqrt().plus(n),T=!0,i.precision=t,i.rounding=e,n.ln())};p.inverseHyperbolicTangent=p.atanh=function(){var t,e,n,i,r=this,o=r.constructor;return r.isFinite()?r.e>=0?new o(r.abs().eq(1)?r.s/0:r.isZero()?r:NaN):(t=o.precision,e=o.rounding,i=r.sd(),Math.max(i,t)<2*-r.e-1?g(new o(r),t,e,!0):(o.precision=n=i-r.e,r=C(r.plus(1),new o(1).minus(r),n+t,1),o.precision=t+4,o.rounding=1,r=r.ln(),o.precision=t,o.rounding=e,r.times(.5))):new o(NaN)};p.inverseSine=p.asin=function(){var t,e,n,i,r=this,o=r.constructor;return r.isZero()?new o(r):(e=r.abs().cmp(1),n=o.precision,i=o.rounding,e!==-1?e===0?(t=J(o,n+4,i).times(.5),t.s=r.s,t):new o(NaN):(o.precision=n+6,o.rounding=1,r=r.div(new o(1).minus(r.times(r)).sqrt().plus(1)).atan(),o.precision=n,o.rounding=i,r.times(2)))};p.inverseTangent=p.atan=function(){var t,e,n,i,r,o,s,a,c,u=this,l=u.constructor,m=l.precision,d=l.rounding;if(u.isFinite()){if(u.isZero())return new l(u);if(u.abs().eq(1)&&m+4<=ut)return s=J(l,m+4,d).times(.25),s.s=u.s,s}else{if(!u.s)return new l(NaN);if(m+4<=ut)return s=J(l,m+4,d).times(.5),s.s=u.s,s}for(l.precision=a=m+10,l.rounding=1,n=Math.min(28,a/A+2|0),t=n;t;--t)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(T=!1,e=Math.ceil(a/A),i=1,c=u.times(u),s=new l(u),r=u;t!==-1;)if(r=r.times(c),o=s.minus(r.div(i+=2)),r=r.times(c),s=o.plus(r.div(i+=2)),s.d[e]!==void 0)for(t=e;s.d[t]===o.d[t]&&t--;);return n&&(s=s.times(2<<n-1)),T=!0,g(s,l.precision=m,l.rounding=d,!0)};p.isFinite=function(){return!!this.d};p.isInteger=p.isInt=function(){return!!this.d&&V(this.e/A)>this.d.length-2};p.isNaN=function(){return!this.s};p.isNegative=p.isNeg=function(){return this.s<0};p.isPositive=p.isPos=function(){return this.s>0};p.isZero=function(){return!!this.d&&this.d[0]===0};p.lessThan=p.lt=function(t){return this.cmp(t)<0};p.lessThanOrEqualTo=p.lte=function(t){return this.cmp(t)<1};p.logarithm=p.log=function(t){var e,n,i,r,o,s,a,c,u=this,l=u.constructor,m=l.precision,d=l.rounding,b=5;if(t==null)t=new l(10),e=!0;else{if(t=new l(t),n=t.d,t.s<0||!n||!n[0]||t.eq(1))return new l(NaN);e=t.eq(10)}if(n=u.d,u.s<0||!n||!n[0]||u.eq(1))return new l(n&&!n[0]?-1/0:u.s!=1?NaN:n?0:1/0);if(e)if(n.length>1)o=!0;else{for(r=n[0];r%10===0;)r/=10;o=r!==1}if(T=!1,a=m+b,s=ue(u,a),i=e?We(l,a+10):ue(t,a),c=C(s,i,a,1),ke(c.d,r=m,d))do if(a+=10,s=ue(u,a),i=e?We(l,a+10):ue(t,a),c=C(s,i,a,1),!o){+D(c.d).slice(r+1,r+15)+1==1e14&&(c=g(c,m+1,0));break}while(ke(c.d,r+=10,d));return T=!0,g(c,m,d)};p.minus=p.sub=function(t){var e,n,i,r,o,s,a,c,u,l,m,d,b=this,h=b.constructor;if(t=new h(t),!b.d||!t.d)return!b.s||!t.s?t=new h(NaN):b.d?t.s=-t.s:t=new h(t.d||b.s!==t.s?b:NaN),t;if(b.s!=t.s)return t.s=-t.s,b.plus(t);if(u=b.d,d=t.d,a=h.precision,c=h.rounding,!u[0]||!d[0]){if(d[0])t.s=-t.s;else if(u[0])t=new h(b);else return new h(c===3?-0:0);return T?g(t,a,c):t}if(n=V(t.e/A),l=V(b.e/A),u=u.slice(),o=l-n,o){for(m=o<0,m?(e=u,o=-o,s=d.length):(e=d,n=l,s=u.length),i=Math.max(Math.ceil(a/A),s)+2,o>i&&(o=i,e.length=1),e.reverse(),i=o;i--;)e.push(0);e.reverse()}else{for(i=u.length,s=d.length,m=i<s,m&&(s=i),i=0;i<s;i++)if(u[i]!=d[i]){m=u[i]<d[i];break}o=0}for(m&&(e=u,u=d,d=e,t.s=-t.s),s=u.length,i=d.length-s;i>0;--i)u[s++]=0;for(i=d.length;i>o;){if(u[--i]<d[i]){for(r=i;r&&u[--r]===0;)u[r]=$-1;--u[r],u[i]+=$}u[i]-=d[i]}for(;u[--s]===0;)u.pop();for(;u[0]===0;u.shift())--n;return u[0]?(t.d=u,t.e=Ge(u,n),T?g(t,a,c):t):new h(c===3?-0:0)};p.modulo=p.mod=function(t){var e,n=this,i=n.constructor;return t=new i(t),!n.d||!t.s||t.d&&!t.d[0]?new i(NaN):!t.d||n.d&&!n.d[0]?g(new i(n),i.precision,i.rounding):(T=!1,i.modulo==9?(e=C(n,t.abs(),0,3,1),e.s*=t.s):e=C(n,t,0,i.modulo,1),e=e.times(t),T=!0,n.minus(e))};p.naturalExponential=p.exp=function(){return ct(this)};p.naturalLogarithm=p.ln=function(){return ue(this)};p.negated=p.neg=function(){var t=new this.constructor(this);return t.s=-t.s,g(t)};p.plus=p.add=function(t){var e,n,i,r,o,s,a,c,u,l,m=this,d=m.constructor;if(t=new d(t),!m.d||!t.d)return!m.s||!t.s?t=new d(NaN):m.d||(t=new d(t.d||m.s===t.s?m:NaN)),t;if(m.s!=t.s)return t.s=-t.s,m.minus(t);if(u=m.d,l=t.d,a=d.precision,c=d.rounding,!u[0]||!l[0])return l[0]||(t=new d(m)),T?g(t,a,c):t;if(o=V(m.e/A),i=V(t.e/A),u=u.slice(),r=o-i,r){for(r<0?(n=u,r=-r,s=l.length):(n=l,i=o,s=u.length),o=Math.ceil(a/A),s=o>s?o+1:s+1,r>s&&(r=s,n.length=1),n.reverse();r--;)n.push(0);n.reverse()}for(s=u.length,r=l.length,s-r<0&&(r=s,n=l,l=u,u=n),e=0;r;)e=(u[--r]=u[r]+l[r]+e)/$|0,u[r]%=$;for(e&&(u.unshift(e),++i),s=u.length;u[--s]==0;)u.pop();return t.d=u,t.e=Ge(u,i),T?g(t,a,c):t};p.precision=p.sd=function(t){var e,n=this;if(t!==void 0&&t!==!!t&&t!==1&&t!==0)throw Error(ce+t);return n.d?(e=Gt(n.d),t&&n.e+1>e&&(e=n.e+1)):e=NaN,e};p.round=function(){var t=this,e=t.constructor;return g(new e(t),t.e+1,e.rounding)};p.sine=p.sin=function(){var t,e,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(t=i.precision,e=i.rounding,i.precision=t+Math.max(n.e,n.sd())+A,i.rounding=1,n=Xn(i,Zt(i,n)),i.precision=t,i.rounding=e,g(oe>2?n.neg():n,t,e,!0)):new i(NaN)};p.squareRoot=p.sqrt=function(){var t,e,n,i,r,o,s=this,a=s.d,c=s.e,u=s.s,l=s.constructor;if(u!==1||!a||!a[0])return new l(!u||u<0&&(!a||a[0])?NaN:a?s:1/0);for(T=!1,u=Math.sqrt(+s),u==0||u==1/0?(e=D(a),(e.length+c)%2==0&&(e+="0"),u=Math.sqrt(e),c=V((c+1)/2)-(c<0||c%2),u==1/0?e="5e"+c:(e=u.toExponential(),e=e.slice(0,e.indexOf("e")+1)+c),i=new l(e)):i=new l(u.toString()),n=(c=l.precision)+3;;)if(o=i,i=o.plus(C(s,o,n+2,1)).times(.5),D(o.d).slice(0,n)===(e=D(i.d)).slice(0,n))if(e=e.slice(n-3,n+1),e=="9999"||!r&&e=="4999"){if(!r&&(g(o,c+1,0),o.times(o).eq(s))){i=o;break}n+=4,r=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(g(i,c+1,1),t=!i.times(i).eq(s));break}return T=!0,g(i,c,l.rounding,t)};p.tangent=p.tan=function(){var t,e,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(t=i.precision,e=i.rounding,i.precision=t+10,i.rounding=1,n=n.sin(),n.s=1,n=C(n,new i(1).minus(n.times(n)).sqrt(),t+10,0),i.precision=t,i.rounding=e,g(oe==2||oe==4?n.neg():n,t,e,!0)):new i(NaN)};p.times=p.mul=function(t){var e,n,i,r,o,s,a,c,u,l=this,m=l.constructor,d=l.d,b=(t=new m(t)).d;if(t.s*=l.s,!d||!d[0]||!b||!b[0])return new m(!t.s||d&&!d[0]&&!b||b&&!b[0]&&!d?NaN:!d||!b?t.s/0:t.s*0);for(n=V(l.e/A)+V(t.e/A),c=d.length,u=b.length,c<u&&(o=d,d=b,b=o,s=c,c=u,u=s),o=[],s=c+u,i=s;i--;)o.push(0);for(i=u;--i>=0;){for(e=0,r=c+i;r>i;)a=o[r]+b[i]*d[r-i-1]+e,o[r--]=a%$|0,e=a/$|0;o[r]=(o[r]+e)%$|0}for(;!o[--s];)o.pop();return e?++n:o.shift(),t.d=o,t.e=Ge(o,n),T?g(t,m.precision,m.rounding):t};p.toBinary=function(t,e){return mt(this,2,t,e)};p.toDecimalPlaces=p.toDP=function(t,e){var n=this,i=n.constructor;return n=new i(n),t===void 0?n:(U(t,0,le),e===void 0?e=i.rounding:U(e,0,8),g(n,t+n.e+1,e))};p.toExponential=function(t,e){var n,i=this,r=i.constructor;return t===void 0?n=te(i,!0):(U(t,0,le),e===void 0?e=r.rounding:U(e,0,8),i=g(new r(i),t+1,e),n=te(i,!0,t+1)),i.isNeg()&&!i.isZero()?"-"+n:n};p.toFixed=function(t,e){var n,i,r=this,o=r.constructor;return t===void 0?n=te(r):(U(t,0,le),e===void 0?e=o.rounding:U(e,0,8),i=g(new o(r),t+r.e+1,e),n=te(i,!1,t+i.e+1)),r.isNeg()&&!r.isZero()?"-"+n:n};p.toFraction=function(t){var e,n,i,r,o,s,a,c,u,l,m,d,b=this,h=b.d,P=b.constructor;if(!h)return new P(b);if(u=n=new P(1),i=c=new P(0),e=new P(i),o=e.e=Gt(h)-b.e-1,s=o%A,e.d[0]=E(10,s<0?A+s:s),t==null)t=o>0?e:u;else{if(a=new P(t),!a.isInt()||a.lt(u))throw Error(ce+a);t=a.gt(e)?o>0?e:u:a}for(T=!1,a=new P(D(h)),l=P.precision,P.precision=o=h.length*A*2;m=C(a,e,0,1,1),r=n.plus(m.times(i)),r.cmp(t)!=1;)n=i,i=r,r=u,u=c.plus(m.times(r)),c=r,r=e,e=a.minus(m.times(r)),a=r;return r=C(t.minus(n),i,0,1,1),c=c.plus(r.times(u)),n=n.plus(r.times(i)),c.s=u.s=b.s,d=C(u,i,o,1).minus(b).abs().cmp(C(c,n,o,1).minus(b).abs())<1?[u,i]:[c,n],P.precision=l,T=!0,d};p.toHexadecimal=p.toHex=function(t,e){return mt(this,16,t,e)};p.toNearest=function(t,e){var n=this,i=n.constructor;if(n=new i(n),t==null){if(!n.d)return n;t=new i(1),e=i.rounding}else{if(t=new i(t),e===void 0?e=i.rounding:U(e,0,8),!n.d)return t.s?n:t;if(!t.d)return t.s&&(t.s=n.s),t}return t.d[0]?(T=!1,n=C(n,t,0,e,1).times(t),T=!0,g(n)):(t.s=n.s,n=t),n};p.toNumber=function(){return+this};p.toOctal=function(t,e){return mt(this,8,t,e)};p.toPower=p.pow=function(t){var e,n,i,r,o,s,a=this,c=a.constructor,u=+(t=new c(t));if(!a.d||!t.d||!a.d[0]||!t.d[0])return new c(E(+a,u));if(a=new c(a),a.eq(1))return a;if(i=c.precision,o=c.rounding,t.eq(1))return g(a,i,o);if(e=V(t.e/A),e>=t.d.length-1&&(n=u<0?-u:u)<=Wn)return r=Ut(c,a,n,i),t.s<0?new c(1).div(r):g(r,i,o);if(s=a.s,s<0){if(e<t.d.length-1)return new c(NaN);if((t.d[e]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return n=E(+a,u),e=n==0||!isFinite(n)?V(u*(Math.log("0."+D(a.d))/Math.LN10+a.e+1)):new c(n+"").e,e>c.maxE+1||e<c.minE-1?new c(e>0?s/0:0):(T=!1,c.rounding=a.s=1,n=Math.min(12,(e+"").length),r=ct(t.times(ue(a,i+n)),i),r.d&&(r=g(r,i+5,1),ke(r.d,i,o)&&(e=i+10,r=g(ct(t.times(ue(a,e+n)),e),e+5,1),+D(r.d).slice(i+1,i+15)+1==1e14&&(r=g(r,i+1,0)))),r.s=s,T=!0,c.rounding=o,g(r,i,o))};p.toPrecision=function(t,e){var n,i=this,r=i.constructor;return t===void 0?n=te(i,i.e<=r.toExpNeg||i.e>=r.toExpPos):(U(t,1,le),e===void 0?e=r.rounding:U(e,0,8),i=g(new r(i),t,e),n=te(i,t<=i.e||i.e<=r.toExpNeg,t)),i.isNeg()&&!i.isZero()?"-"+n:n};p.toSignificantDigits=p.toSD=function(t,e){var n=this,i=n.constructor;return t===void 0?(t=i.precision,e=i.rounding):(U(t,1,le),e===void 0?e=i.rounding:U(e,0,8)),g(new i(n),t,e)};p.toString=function(){var t=this,e=t.constructor,n=te(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()&&!t.isZero()?"-"+n:n};p.truncated=p.trunc=function(){return g(new this.constructor(this),this.e+1,1)};p.valueOf=p.toJSON=function(){var t=this,e=t.constructor,n=te(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()?"-"+n:n};function D(t){var e,n,i,r=t.length-1,o="",s=t[0];if(r>0){for(o+=s,e=1;e<r;e++)i=t[e]+"",n=A-i.length,n&&(o+=ae(n)),o+=i;s=t[e],i=s+"",n=A-i.length,n&&(o+=ae(n))}else if(s===0)return"0";for(;s%10===0;)s/=10;return o+s}function U(t,e,n){if(t!==~~t||t<e||t>n)throw Error(ce+t)}function ke(t,e,n,i){var r,o,s,a;for(o=t[0];o>=10;o/=10)--e;return--e<0?(e+=A,r=0):(r=Math.ceil((e+1)/A),e%=A),o=E(10,A-e),a=t[r]%o|0,i==null?e<3?(e==0?a=a/100|0:e==1&&(a=a/10|0),s=n<4&&a==99999||n>3&&a==49999||a==5e4||a==0):s=(n<4&&a+1==o||n>3&&a+1==o/2)&&(t[r+1]/o/100|0)==E(10,e-2)-1||(a==o/2||a==0)&&(t[r+1]/o/100|0)==0:e<4?(e==0?a=a/1e3|0:e==1?a=a/100|0:e==2&&(a=a/10|0),s=(i||n<4)&&a==9999||!i&&n>3&&a==4999):s=((i||n<4)&&a+1==o||!i&&n>3&&a+1==o/2)&&(t[r+1]/o/1e3|0)==E(10,e-3)-1,s}function De(t,e,n){for(var i,r=[0],o,s=0,a=t.length;s<a;){for(o=r.length;o--;)r[o]*=e;for(r[0]+=st.indexOf(t.charAt(s++)),i=0;i<r.length;i++)r[i]>n-1&&(r[i+1]===void 0&&(r[i+1]=0),r[i+1]+=r[i]/n|0,r[i]%=n)}return r.reverse()}function Gn(t,e){var n,i,r;if(e.isZero())return e;i=e.d.length,i<32?(n=Math.ceil(i/3),r=(1/Ue(4,n)).toString()):(n=16,r="2.3283064365386962890625e-10"),t.precision+=n,e=ye(t,1,e.times(r),new t(1));for(var o=n;o--;){var s=e.times(e);e=s.times(s).minus(s).times(8).plus(1)}return t.precision-=n,e}var C=function(){function t(i,r,o){var s,a=0,c=i.length;for(i=i.slice();c--;)s=i[c]*r+a,i[c]=s%o|0,a=s/o|0;return a&&i.unshift(a),i}function e(i,r,o,s){var a,c;if(o!=s)c=o>s?1:-1;else for(a=c=0;a<o;a++)if(i[a]!=r[a]){c=i[a]>r[a]?1:-1;break}return c}function n(i,r,o,s){for(var a=0;o--;)i[o]-=a,a=i[o]<r[o]?1:0,i[o]=a*s+i[o]-r[o];for(;!i[0]&&i.length>1;)i.shift()}return function(i,r,o,s,a,c){var u,l,m,d,b,h,P,F,I,v,B,O,be,z,he,Oe,Te,rt,Y,Ee,ve=i.constructor,ot=i.s==r.s?1:-1,_=i.d,N=r.d;if(!_||!_[0]||!N||!N[0])return new ve(!i.s||!r.s||(_?N&&_[0]==N[0]:!N)?NaN:_&&_[0]==0||!N?ot*0:ot/0);for(c?(b=1,l=i.e-r.e):(c=$,b=A,l=V(i.e/b)-V(r.e/b)),Y=N.length,Te=_.length,I=new ve(ot),v=I.d=[],m=0;N[m]==(_[m]||0);m++);if(N[m]>(_[m]||0)&&l--,o==null?(z=o=ve.precision,s=ve.rounding):a?z=o+(i.e-r.e)+1:z=o,z<0)v.push(1),h=!0;else{if(z=z/b+2|0,m=0,Y==1){for(d=0,N=N[0],z++;(m<Te||d)&&z--;m++)he=d*c+(_[m]||0),v[m]=he/N|0,d=he%N|0;h=d||m<Te}else{for(d=c/(N[0]+1)|0,d>1&&(N=t(N,d,c),_=t(_,d,c),Y=N.length,Te=_.length),Oe=Y,B=_.slice(0,Y),O=B.length;O<Y;)B[O++]=0;Ee=N.slice(),Ee.unshift(0),rt=N[0],N[1]>=c/2&&++rt;do d=0,u=e(N,B,Y,O),u<0?(be=B[0],Y!=O&&(be=be*c+(B[1]||0)),d=be/rt|0,d>1?(d>=c&&(d=c-1),P=t(N,d,c),F=P.length,O=B.length,u=e(P,B,F,O),u==1&&(d--,n(P,Y<F?Ee:N,F,c))):(d==0&&(u=d=1),P=N.slice()),F=P.length,F<O&&P.unshift(0),n(B,P,O,c),u==-1&&(O=B.length,u=e(N,B,Y,O),u<1&&(d++,n(B,Y<O?Ee:N,O,c))),O=B.length):u===0&&(d++,B=[0]),v[m++]=d,u&&B[0]?B[O++]=_[Oe]||0:(B=[_[Oe]],O=1);while((Oe++<Te||B[0]!==void 0)&&z--);h=B[0]!==void 0}v[0]||v.shift()}if(b==1)I.e=l,Dt=h;else{for(m=1,d=v[0];d>=10;d/=10)m++;I.e=m+l*b-1,g(I,a?o+I.e+1:o,s,h)}return I}}();function g(t,e,n,i){var r,o,s,a,c,u,l,m,d,b=t.constructor;e:if(e!=null){if(m=t.d,!m)return t;for(r=1,a=m[0];a>=10;a/=10)r++;if(o=e-r,o<0)o+=A,s=e,l=m[d=0],c=l/E(10,r-s-1)%10|0;else if(d=Math.ceil((o+1)/A),a=m.length,d>=a)if(i){for(;a++<=d;)m.push(0);l=c=0,r=1,o%=A,s=o-A+1}else break e;else{for(l=a=m[d],r=1;a>=10;a/=10)r++;o%=A,s=o-A+r,c=s<0?0:l/E(10,r-s-1)%10|0}if(i=i||e<0||m[d+1]!==void 0||(s<0?l:l%E(10,r-s-1)),u=n<4?(c||i)&&(n==0||n==(t.s<0?3:2)):c>5||c==5&&(n==4||i||n==6&&(o>0?s>0?l/E(10,r-s):0:m[d-1])%10&1||n==(t.s<0?8:7)),e<1||!m[0])return m.length=0,u?(e-=t.e+1,m[0]=E(10,(A-e%A)%A),t.e=-e||0):m[0]=t.e=0,t;if(o==0?(m.length=d,a=1,d--):(m.length=d+1,a=E(10,A-o),m[d]=s>0?(l/E(10,r-s)%E(10,s)|0)*a:0),u)for(;;)if(d==0){for(o=1,s=m[0];s>=10;s/=10)o++;for(s=m[0]+=a,a=1;s>=10;s/=10)a++;o!=a&&(t.e++,m[0]==$&&(m[0]=1));break}else{if(m[d]+=a,m[d]!=$)break;m[d--]=0,a=1}for(o=m.length;m[--o]===0;)m.pop()}return T&&(t.e>b.maxE?(t.d=null,t.e=NaN):t.e<b.minE&&(t.e=0,t.d=[0])),t}function te(t,e,n){if(!t.isFinite())return Ht(t);var i,r=t.e,o=D(t.d),s=o.length;return e?(n&&(i=n-s)>0?o=o.charAt(0)+"."+o.slice(1)+ae(i):s>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(t.e<0?"e":"e+")+t.e):r<0?(o="0."+ae(-r-1)+o,n&&(i=n-s)>0&&(o+=ae(i))):r>=s?(o+=ae(r+1-s),n&&(i=n-r-1)>0&&(o=o+"."+ae(i))):((i=r+1)<s&&(o=o.slice(0,i)+"."+o.slice(i)),n&&(i=n-s)>0&&(r+1===s&&(o+="."),o+=ae(i))),o}function Ge(t,e){var n=t[0];for(e*=A;n>=10;n/=10)e++;return e}function We(t,e,n){if(e>qn)throw T=!0,n&&(t.precision=n),Error(_t);return g(new t(_e),e,1,!0)}function J(t,e,n){if(e>ut)throw Error(_t);return g(new t(Ve),e,n,!0)}function Gt(t){var e=t.length-1,n=e*A+1;if(e=t[e],e){for(;e%10==0;e/=10)n--;for(e=t[0];e>=10;e/=10)n++}return n}function ae(t){for(var e="";t--;)e+="0";return e}function Ut(t,e,n,i){var r,o=new t(1),s=Math.ceil(i/A+4);for(T=!1;;){if(n%2&&(o=o.times(e),Et(o.d,s)&&(r=!0)),n=V(n/2),n===0){n=o.d.length-1,r&&o.d[n]===0&&++o.d[n];break}e=e.times(e),Et(e.d,s)}return T=!0,o}function Ot(t){return t.d[t.d.length-1]&1}function Xt(t,e,n){for(var i,r=new t(e[0]),o=0;++o<e.length;)if(i=new t(e[o]),i.s)r[n](i)&&(r=i);else{r=i;break}return r}function ct(t,e){var n,i,r,o,s,a,c,u=0,l=0,m=0,d=t.constructor,b=d.rounding,h=d.precision;if(!t.d||!t.d[0]||t.e>17)return new d(t.d?t.d[0]?t.s<0?0:1/0:1:t.s?t.s<0?0:t:0/0);for(e==null?(T=!1,c=h):c=e,a=new d(.03125);t.e>-2;)t=t.times(a),m+=5;for(i=Math.log(E(2,m))/Math.LN10*2+5|0,c+=i,n=o=s=new d(1),d.precision=c;;){if(o=g(o.times(t),c,1),n=n.times(++l),a=s.plus(C(o,n,c,1)),D(a.d).slice(0,c)===D(s.d).slice(0,c)){for(r=m;r--;)s=g(s.times(s),c,1);if(e==null)if(u<3&&ke(s.d,c-i,b,u))d.precision=c+=10,n=o=a=new d(1),l=0,u++;else return g(s,d.precision=h,b,T=!0);else return d.precision=h,s}s=a}}function ue(t,e){var n,i,r,o,s,a,c,u,l,m,d,b=1,h=10,P=t,F=P.d,I=P.constructor,v=I.rounding,B=I.precision;if(P.s<0||!F||!F[0]||!P.e&&F[0]==1&&F.length==1)return new I(F&&!F[0]?-1/0:P.s!=1?NaN:F?0:P);if(e==null?(T=!1,l=B):l=e,I.precision=l+=h,n=D(F),i=n.charAt(0),Math.abs(o=P.e)<15e14){for(;i<7&&i!=1||i==1&&n.charAt(1)>3;)P=P.times(t),n=D(P.d),i=n.charAt(0),b++;o=P.e,i>1?(P=new I("0."+n),o++):P=new I(i+"."+n.slice(1))}else return u=We(I,l+2,B).times(o+""),P=ue(new I(i+"."+n.slice(1)),l-h).plus(u),I.precision=B,e==null?g(P,B,v,T=!0):P;for(m=P,c=s=P=C(P.minus(1),P.plus(1),l,1),d=g(P.times(P),l,1),r=3;;){if(s=g(s.times(d),l,1),u=c.plus(C(s,new I(r),l,1)),D(u.d).slice(0,l)===D(c.d).slice(0,l))if(c=c.times(2),o!==0&&(c=c.plus(We(I,l+2,B).times(o+""))),c=C(c,new I(b),l,1),e==null)if(ke(c.d,l-h,v,a))I.precision=l+=h,u=s=P=C(m.minus(1),m.plus(1),l,1),d=g(P.times(P),l,1),r=a=1;else return g(c,I.precision=B,v,T=!0);else return I.precision=B,c;c=u,r+=2}}function Ht(t){return String(t.s*t.s/0)}function lt(t,e){var n,i,r;for((n=e.indexOf("."))>-1&&(e=e.replace(".","")),(i=e.search(/e/i))>0?(n<0&&(n=i),n+=+e.slice(i+1),e=e.substring(0,i)):n<0&&(n=e.length),i=0;e.charCodeAt(i)===48;i++);for(r=e.length;e.charCodeAt(r-1)===48;--r);if(e=e.slice(i,r),e){if(r-=i,t.e=n=n-i-1,t.d=[],i=(n+1)%A,n<0&&(i+=A),i<r){for(i&&t.d.push(+e.slice(0,i)),r-=A;i<r;)t.d.push(+e.slice(i,i+=A));e=e.slice(i),i=A-e.length}else i-=r;for(;i--;)e+="0";t.d.push(+e),T&&(t.e>t.constructor.maxE?(t.d=null,t.e=NaN):t.e<t.constructor.minE&&(t.e=0,t.d=[0]))}else t.e=0,t.d=[0];return t}function Un(t,e){var n,i,r,o,s,a,c,u,l;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),qt.test(e))return lt(t,e)}else if(e==="Infinity"||e==="NaN")return+e||(t.s=NaN),t.e=NaN,t.d=null,t;if(_n.test(e))n=16,e=e.toLowerCase();else if(Dn.test(e))n=2;else if(Vn.test(e))n=8;else throw Error(ce+e);for(o=e.search(/p/i),o>0?(c=+e.slice(o+1),e=e.substring(2,o)):e=e.slice(2),o=e.indexOf("."),s=o>=0,i=t.constructor,s&&(e=e.replace(".",""),a=e.length,o=a-o,r=Ut(i,new i(n),o,o*2)),u=De(e,n,$),l=u.length-1,o=l;u[o]===0;--o)u.pop();return o<0?new i(t.s*0):(t.e=Ge(u,l),t.d=u,T=!1,s&&(t=C(t,r,a*4)),c&&(t=t.times(Math.abs(c)<54?E(2,c):Be.pow(2,c))),T=!0,t)}function Xn(t,e){var n,i=e.d.length;if(i<3)return e.isZero()?e:ye(t,2,e,e);n=1.4*Math.sqrt(i),n=n>16?16:n|0,e=e.times(1/Ue(5,n)),e=ye(t,2,e,e);for(var r,o=new t(5),s=new t(16),a=new t(20);n--;)r=e.times(e),e=e.times(o.plus(r.times(s.times(r).minus(a))));return e}function ye(t,e,n,i,r){var o,s,a,c,u=1,l=t.precision,m=Math.ceil(l/A);for(T=!1,c=n.times(n),a=new t(i);;){if(s=C(a.times(c),new t(e++*e++),l,1),a=r?i.plus(s):i.minus(s),i=C(s.times(c),new t(e++*e++),l,1),s=a.plus(i),s.d[m]!==void 0){for(o=m;s.d[o]===a.d[o]&&o--;);if(o==-1)break}o=a,a=i,i=s,s=o,u++}return T=!0,s.d.length=m+1,s}function Ue(t,e){for(var n=t;--e;)n*=t;return n}function Zt(t,e){var n,i=e.s<0,r=J(t,t.precision,1),o=r.times(.5);if(e=e.abs(),e.lte(o))return oe=i?4:1,e;if(n=e.divToInt(r),n.isZero())oe=i?3:2;else{if(e=e.minus(n.times(r)),e.lte(o))return oe=Ot(n)?i?2:3:i?4:1,e;oe=Ot(n)?i?1:4:i?3:2}return e.minus(r).abs()}function mt(t,e,n,i){var r,o,s,a,c,u,l,m,d,b=t.constructor,h=n!==void 0;if(h?(U(n,1,le),i===void 0?i=b.rounding:U(i,0,8)):(n=b.precision,i=b.rounding),!t.isFinite())l=Ht(t);else{for(l=te(t),s=l.indexOf("."),h?(r=2,e==16?n=n*4-3:e==8&&(n=n*3-2)):r=e,s>=0&&(l=l.replace(".",""),d=new b(1),d.e=l.length-s,d.d=De(te(d),10,r),d.e=d.d.length),m=De(l,10,r),o=c=m.length;m[--c]==0;)m.pop();if(!m[0])l=h?"0p+0":"0";else{if(s<0?o--:(t=new b(t),t.d=m,t.e=o,t=C(t,d,n,i,0,r),m=t.d,o=t.e,u=Dt),s=m[n],a=r/2,u=u||m[n+1]!==void 0,u=i<4?(s!==void 0||u)&&(i===0||i===(t.s<0?3:2)):s>a||s===a&&(i===4||u||i===6&&m[n-1]&1||i===(t.s<0?8:7)),m.length=n,u)for(;++m[--n]>r-1;)m[n]=0,n||(++o,m.unshift(1));for(c=m.length;!m[c-1];--c);for(s=0,l="";s<c;s++)l+=st.charAt(m[s]);if(h){if(c>1)if(e==16||e==8){for(s=e==16?4:3,--c;c%s;c++)l+="0";for(m=De(l,r,e),c=m.length;!m[c-1];--c);for(s=1,l="1.";s<c;s++)l+=st.charAt(m[s])}else l=l.charAt(0)+"."+l.slice(1);l=l+(o<0?"p":"p+")+o}else if(o<0){for(;++o;)l="0"+l;l="0."+l}else if(++o>c)for(o-=c;o--;)l+="0";else o<c&&(l=l.slice(0,o)+"."+l.slice(o))}l=(e==16?"0x":e==2?"0b":e==8?"0o":"")+l}return t.s<0?"-"+l:l}function Et(t,e){if(t.length>e)return t.length=e,!0}function Hn(t){return new this(t).abs()}function Zn(t){return new this(t).acos()}function zn(t){return new this(t).acosh()}function jn(t,e){return new this(t).plus(e)}function Qn(t){return new this(t).asin()}function Yn(t){return new this(t).asinh()}function Jn(t){return new this(t).atan()}function $n(t){return new this(t).atanh()}function ei(t,e){t=new this(t),e=new this(e);var n,i=this.precision,r=this.rounding,o=i+4;return!t.s||!e.s?n=new this(NaN):!t.d&&!e.d?(n=J(this,o,1).times(e.s>0?.25:.75),n.s=t.s):!e.d||t.isZero()?(n=e.s<0?J(this,i,r):new this(0),n.s=t.s):!t.d||e.isZero()?(n=J(this,o,1).times(.5),n.s=t.s):e.s<0?(this.precision=o,this.rounding=1,n=this.atan(C(t,e,o,1)),e=J(this,o,1),this.precision=i,this.rounding=r,n=t.s<0?n.minus(e):n.plus(e)):n=this.atan(C(t,e,o,1)),n}function ti(t){return new this(t).cbrt()}function ni(t){return g(t=new this(t),t.e+1,2)}function ii(t,e,n){return new this(t).clamp(e,n)}function ri(t){if(!t||typeof t!="object")throw Error(qe+"Object expected");var e,n,i,r=t.defaults===!0,o=["precision",1,le,"rounding",0,8,"toExpNeg",-ge,0,"toExpPos",0,ge,"maxE",0,ge,"minE",-ge,0,"modulo",0,9];for(e=0;e<o.length;e+=3)if(n=o[e],r&&(this[n]=at[n]),(i=t[n])!==void 0)if(V(i)===i&&i>=o[e+1]&&i<=o[e+2])this[n]=i;else throw Error(ce+n+": "+i);if(n="crypto",r&&(this[n]=at[n]),(i=t[n])!==void 0)if(i===!0||i===!1||i===0||i===1)if(i)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(Vt);else this[n]=!1;else throw Error(ce+n+": "+i);return this}function oi(t){return new this(t).cos()}function si(t){return new this(t).cosh()}function zt(t){var e,n,i;function r(o){var s,a,c,u=this;if(!(u instanceof r))return new r(o);if(u.constructor=r,vt(o)){u.s=o.s,T?!o.d||o.e>r.maxE?(u.e=NaN,u.d=null):o.e<r.minE?(u.e=0,u.d=[0]):(u.e=o.e,u.d=o.d.slice()):(u.e=o.e,u.d=o.d?o.d.slice():o.d);return}if(c=typeof o,c==="number"){if(o===0){u.s=1/o<0?-1:1,u.e=0,u.d=[0];return}if(o<0?(o=-o,u.s=-1):u.s=1,o===~~o&&o<1e7){for(s=0,a=o;a>=10;a/=10)s++;T?s>r.maxE?(u.e=NaN,u.d=null):s<r.minE?(u.e=0,u.d=[0]):(u.e=s,u.d=[o]):(u.e=s,u.d=[o]);return}else if(o*0!==0){o||(u.s=NaN),u.e=NaN,u.d=null;return}return lt(u,o.toString())}else if(c!=="string")throw Error(ce+o);return(a=o.charCodeAt(0))===45?(o=o.slice(1),u.s=-1):(a===43&&(o=o.slice(1)),u.s=1),qt.test(o)?lt(u,o):Un(u,o)}if(r.prototype=p,r.ROUND_UP=0,r.ROUND_DOWN=1,r.ROUND_CEIL=2,r.ROUND_FLOOR=3,r.ROUND_HALF_UP=4,r.ROUND_HALF_DOWN=5,r.ROUND_HALF_EVEN=6,r.ROUND_HALF_CEIL=7,r.ROUND_HALF_FLOOR=8,r.EUCLID=9,r.config=r.set=ri,r.clone=zt,r.isDecimal=vt,r.abs=Hn,r.acos=Zn,r.acosh=zn,r.add=jn,r.asin=Qn,r.asinh=Yn,r.atan=Jn,r.atanh=$n,r.atan2=ei,r.cbrt=ti,r.ceil=ni,r.clamp=ii,r.cos=oi,r.cosh=si,r.div=ai,r.exp=ui,r.floor=ci,r.hypot=li,r.ln=mi,r.log=di,r.log10=fi,r.log2=pi,r.max=bi,r.min=gi,r.mod=yi,r.mul=wi,r.pow=Pi,r.random=Ai,r.round=hi,r.sign=Ti,r.sin=ki,r.sinh=Bi,r.sqrt=xi,r.sub=Ii,r.sum=Si,r.tan=Ci,r.tanh=Ni,r.trunc=Ki,t===void 0&&(t={}),t&&t.defaults!==!0)for(i=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],e=0;e<i.length;)t.hasOwnProperty(n=i[e++])||(t[n]=this[n]);return r.config(t),r}function ai(t,e){return new this(t).div(e)}function ui(t){return new this(t).exp()}function ci(t){return g(t=new this(t),t.e+1,3)}function li(){var t,e,n=new this(0);for(T=!1,t=0;t<arguments.length;)if(e=new this(arguments[t++]),e.d)n.d&&(n=n.plus(e.times(e)));else{if(e.s)return T=!0,new this(1/0);n=e}return T=!0,n.sqrt()}function vt(t){return t instanceof Be||t&&t.toStringTag===Wt||!1}function mi(t){return new this(t).ln()}function di(t,e){return new this(t).log(e)}function pi(t){return new this(t).log(2)}function fi(t){return new this(t).log(10)}function bi(){return Xt(this,arguments,"lt")}function gi(){return Xt(this,arguments,"gt")}function yi(t,e){return new this(t).mod(e)}function wi(t,e){return new this(t).mul(e)}function Pi(t,e){return new this(t).pow(e)}function Ai(t){var e,n,i,r,o=0,s=new this(1),a=[];if(t===void 0?t=this.precision:U(t,1,le),i=Math.ceil(t/A),this.crypto)if(crypto.getRandomValues)for(e=crypto.getRandomValues(new Uint32Array(i));o<i;)r=e[o],r>=429e7?e[o]=crypto.getRandomValues(new Uint32Array(1))[0]:a[o++]=r%1e7;else if(crypto.randomBytes){for(e=crypto.randomBytes(i*=4);o<i;)r=e[o]+(e[o+1]<<8)+(e[o+2]<<16)+((e[o+3]&127)<<24),r>=214e7?crypto.randomBytes(4).copy(e,o):(a.push(r%1e7),o+=4);o=i/4}else throw Error(Vt);else for(;o<i;)a[o++]=Math.random()*1e7|0;for(i=a[--o],t%=A,i&&t&&(r=E(10,A-t),a[o]=(i/r|0)*r);a[o]===0;o--)a.pop();if(o<0)n=0,a=[0];else{for(n=-1;a[0]===0;n-=A)a.shift();for(i=1,r=a[0];r>=10;r/=10)i++;i<A&&(n-=A-i)}return s.e=n,s.d=a,s}function hi(t){return g(t=new this(t),t.e+1,this.rounding)}function Ti(t){return t=new this(t),t.d?t.d[0]?t.s:0*t.s:t.s||NaN}function ki(t){return new this(t).sin()}function Bi(t){return new this(t).sinh()}function xi(t){return new this(t).sqrt()}function Ii(t,e){return new this(t).sub(e)}function Si(){var t=0,e=arguments,n=new this(e[t]);for(T=!1;n.s&&++t<e.length;)n=n.plus(e[t]);return T=!0,g(n,this.precision,this.rounding)}function Ci(t){return new this(t).tan()}function Ni(t){return new this(t).tanh()}function Ki(t){return g(t=new this(t),t.e+1,1)}p[Symbol.for("nodejs.util.inspect.custom")]=p.toString;p[Symbol.toStringTag]="Decimal";var Be=p.constructor=zt(at);_e=new Be(_e);Ve=new Be(Ve);var x=Be;import{PublicKey as zr}from"@solana/web3.js";import{get as jt,set as Li}from"lodash";var dt=class{constructor(e){this.logLevel=e.logLevel!==void 0?e.logLevel:0,this.name=e.name}set level(e){this.logLevel=e}get time(){return Date.now().toString()}get moduleName(){return this.name}isLogLevel(e){return e<=this.logLevel}error(...e){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...e),this):this}logWithError(...e){let n=e.map(i=>typeof i=="object"?JSON.stringify(i):i).join(", ");throw new Error(n)}warning(...e){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...e),this):this}info(...e){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...e),this):this}debug(...e){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...e),this):this}},Qt={},Ri={};function q(t){let e=jt(Qt,t);if(!e){let n=jt(Ri,t);e=new dt({name:t,logLevel:n}),Li(Qt,t,e)}return e}import{MINT_SIZE as Jr,TOKEN_PROGRAM_ID as $r,getTransferFeeConfig as eo,unpackMint as to}from"@solana/spl-token";var no=q("Raydium_accountInfo_util");import ie from"bn.js";import Vi from"big.js";import ho from"bn.js";import Mi from"toformat";var Fi=Mi,xe=Fi;import Ze from"big.js";import Ei from"bn.js";import vi from"decimal.js-light";import Ie from"bn.js";var Jt=9007199254740991;function ne(t){let e=q("Raydium_parseBigNumberish");if(t instanceof Ie)return t;if(typeof t=="string"){if(t.match(/^-?[0-9]+$/))return new Ie(t);e.logWithError(`invalid BigNumberish string: ${t}`)}return typeof t=="number"?(t%1&&e.logWithError(`BigNumberish number underflow: ${t}`),(t>=Jt||t<=-Jt)&&e.logWithError(`BigNumberish number overflow: ${t}`),new Ie(String(t))):typeof t=="bigint"?new Ie(t.toString()):(e.error(`invalid BigNumberish value: ${t}`),new Ie(0))}var He=q("module/fraction"),pt=xe(Ze),Se=xe(vi),Di={[0]:Se.ROUND_DOWN,[1]:Se.ROUND_HALF_UP,[2]:Se.ROUND_UP},_i={[0]:Ze.roundDown,[1]:Ze.roundHalfUp,[2]:Ze.roundUp},K=class{constructor(e,n=new Ei(1)){this.numerator=ne(e),this.denominator=ne(n)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new K(this.denominator,this.numerator)}add(e){let n=e instanceof K?e:new K(ne(e));return this.denominator.eq(n.denominator)?new K(this.numerator.add(n.numerator),this.denominator):new K(this.numerator.mul(n.denominator).add(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}sub(e){let n=e instanceof K?e:new K(ne(e));return this.denominator.eq(n.denominator)?new K(this.numerator.sub(n.numerator),this.denominator):new K(this.numerator.mul(n.denominator).sub(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}mul(e){let n=e instanceof K?e:new K(ne(e));return new K(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(e){let n=e instanceof K?e:new K(ne(e));return new K(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(e,n={groupSeparator:""},i=1){Number.isInteger(e)||He.logWithError(`${e} is not an integer.`),e<=0&&He.logWithError(`${e} is not positive.`),Se.set({precision:e+1,rounding:Di[i]});let r=new Se(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return r.toFormat(r.decimalPlaces(),n)}toFixed(e,n={groupSeparator:""},i=1){return Number.isInteger(e)||He.logWithError(`${e} is not an integer.`),e<0&&He.logWithError(`${e} is negative.`),pt.DP=e,pt.RM=_i[i]||1,new pt(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,n)}isZero(){return this.numerator.isZero()}};var Ko=q("Raydium_amount"),Lo=xe(Vi);import{PublicKey as qi}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as $t}from"@solana/spl-token";var ft={chainId:101,address:qi.default.toBase58(),programId:$t.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},me={chainId:101,address:"So11111111111111111111111111111111111111112",programId:$t.toBase58(),decimals:9,symbol:"WSOL",name:"Wrapped SOL",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}};import{PublicKey as gt}from"@solana/web3.js";import{PublicKey as L,SystemProgram as en,SYSVAR_RENT_PUBKEY as Gi}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Ui}from"@solana/spl-token";function bt({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var _o=[bt({pubkey:Ui,isWritable:!1}),bt({pubkey:en.programId,isWritable:!1}),bt({pubkey:Gi,isWritable:!1})];function tn({publicKey:t,transformSol:e}){let n=nn(t.toString());if(n instanceof L)return e&&n.equals(Ce)?Xe:n;if(e&&n.toString()===Ce.toBase58())return Xe;if(typeof n=="string"){if(n===L.default.toBase58())return L.default;try{return new L(n)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function nn(t){try{return new L(t)}catch{return t}}var Xi=new L("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Hi=new L("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Zi=new L("SysvarRent111111111111111111111111111111111"),Vo=new L("SysvarC1ock11111111111111111111111111111111"),rn=new L("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Wo=new L("Sysvar1nstructions1111111111111111111111111"),qo=en.programId,Go=new L("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Uo=new L("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Xo=new L("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Ho=new L("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Zo=new L("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),zo=new L("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),jo=new L("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Qo=new L("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Yo=new L("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Jo=new L("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),$o=new L("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),Xe=new L("So11111111111111111111111111111111111111112"),Ce=L.default;var yt=class{constructor({mint:e,decimals:n,symbol:i,name:r,skipMint:o=!1,isToken2022:s=!1}){if(e===Ce.toBase58()||e instanceof gt&&Ce.equals(e)){this.decimals=me.decimals,this.symbol=me.symbol,this.name=me.name,this.mint=new gt(me.address),this.isToken2022=!1;return}this.decimals=n,this.symbol=i||e.toString().substring(0,6),this.name=r||e.toString().substring(0,6),this.mint=o?gt.default:tn({publicKey:e}),this.isToken2022=s}equals(e){return this===e?!0:this.mint.equals(e.mint)}},de=yt;de.WSOL=new yt(j(H({},me),{mint:me.address}));var wt=class{constructor({decimals:e,symbol:n="UNKNOWN",name:i="UNKNOWN"}){this.decimals=e,this.symbol=n,this.name=i}equals(e){return this===e}},ze=wt;ze.SOL=new wt(ft);import zi from"bn.js";var ms=new K(new zi(100));var ys=q("Raydium_price");import{PublicKey as Fs}from"@solana/web3.js";import Es from"bn.js";var ji=new ie(0),ea=new ie(1),ta=new ie(2),na=new ie(3),ia=new ie(5),Wi=new ie(10),ra=new ie(100),oa=new ie(1e3),sa=new ie(1e4);function on(t,e,n){return t.mul(e).add(n).sub(new ie(1)).div(n)}import{PublicKey as La}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Ma}from"@solana/spl-token";import{ComputeBudgetProgram as fa,Keypair as ya,PublicKey as wa,Transaction as Aa,TransactionMessage as Ta,VersionedTransaction as ka}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Sa}from"@solana/spl-token";var Ca=q("Raydium_txUtil");import{PublicKey as f}from"@solana/web3.js";var va=new f("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),Da=new f("CBuCnLe26faBpcBP2fktp4rp8abpcAnTWft6ZrP5Q4T"),_a=new f("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),Va=new f("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),Wa=new f("Ray1111111111111111111111111111111111111111"),qa=new f("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),Ga=new f("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),Ua=new f("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),Xa=new f("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),Ha=new f("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),Za=new f("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),Yi=new f("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),Ji=new f("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),$i=new f("kN1kEznaF5Xbd8LYuqtEFcxzWSBk5Fv6ygX6SqEGJVy"),za=new f("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),sn=new f("Ray1111111111111111111111111111111111111111"),ja=new f("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),Qa=new f("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),Ya=new f("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),Ja=new f("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),$a=new f("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),eu=new f("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),tu=new f("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),nu=new f("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),iu=new f("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),er=new f("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),tr=new f("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),nr=new f("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2"),ru=new f("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),ir=new f("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),ou=new f("3f7GcQFG397GAaEnv51zR6tsTVihYRydnydDD1cXekxH"),rr=new f("7AFUeLVRjBfzqK3tTGw8hN48KLQWSk6DTE8xprWdPqix"),su=new f("LanMV9sAd7wArD4vJFi2qDdfnVhFxYSUg6eADduJ3uj"),au=new f("WLHv2UAZm6z4KyaaELi5pjdbJh6RESMva1Rnn8pJVVh"),or=new f("LanD8FpTBBvzZFXjTxsAoipkFsxPUCDB4qAqKxYDiNP"),sr=new f("HYNHiyKJ3gGVFvyxJAurK7qr7P2o5J9THmvCGMdULtpW"),uu=new f("4Bu96XjU84XjPDSpveTVf6LYGCkfW5FK7SNkREWcEfV4"),an=new f("2Jx4KTDrVSdWNazuGpcA8n3ZLTRGGBDxAWhuKe2Xcj2a"),cu=new f("6s1xP3hpbAfFoNtUNF8mfHsjr2Bd97JxFJRWLbL6aHuX"),un=new f("7ZR4zD7PYfY2XxoG1Gxcy2EgEeGYrpxrwzPuwdUBssEt");var lu={AMM_V4:new f("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),AMM_STABLE:new f("DDg4VmQaJV9ogWce7LpcjBA9bv22wRp5uaTPa5pGjijF"),CLMM_PROGRAM_ID:new f("devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH"),CLMM_LOCK_PROGRAM_ID:new f("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),CLMM_LOCK_AUTH_ID:new f("8qmHNvu2Kr2C7U8mJL4Vz1vTDxMhVuXKREwU7TNoaVEo"),FARM_PROGRAM_ID_V3:new f("85BFyr98MbCUU9MVTEgzx1nbhWACbJqLzho6zd6DZcWL"),FARM_PROGRAM_ID_V5:new f("EcLzTrNg9V7qhcdyXDe2qjtPkiGzDM2UbdRaeaadU5r2"),FARM_PROGRAM_ID_V6:new f("Farm2hJLcqPtPg8M4rR6DMrsRNc5TPm5Cs4bVQrMe2T7"),OPEN_BOOK_PROGRAM:new f("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),SERUM_PROGRAM_ID_V3:f.default,UTIL1216:f.default,Router:new f("BVChZ3XFEwTMUk1o9i3HAf91H6mFxSwa5X2wFAWhYPhU"),CREATE_CPMM_POOL_PROGRAM:er,CREATE_CPMM_POOL_AUTH:tr,CREATE_CPMM_POOL_FEE_ACC:nr,LOCK_CPMM_PROGRAM:ir,LOCK_CPMM_AUTH:rr,LAUNCHPAD_PROGRAM:or,LAUNCHPAD_AUTH:sr,LAUNCHPAD_PLATFORM:an,LAUNCHPAD_CONFIG:un,FEE_DESTINATION_ID:new f("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR"),MODEL_DATA_PUBKEY:sn},mu={OPEN_BOOK_PROGRAM:new f("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),SERUM_PROGRAM_ID_V3:new f("Ray1111111111111111111111111111111111111111"),AMM_V4:new f("DRaya7Kj3aMWQSy19kSjvmuwq9docCHofyP9kanQGaav"),AMM_STABLE:new f("DRayDdXc1NZQ9C3hRWmoSf8zK4iapgMnjdNZWrfwsP8m"),CLMM_PROGRAM_ID:new f("DRayAUgENGQBKVaX8owNhgzkEDyoHTGVEGHVJT1E9pfH"),CLMM_LOCK_PROGRAM_ID:new f("DRay25Usp3YJAi7beckgpGUC7mGJ2cR1AVPxhYfwVCUX"),CLMM_LOCK_AUTH_ID:new f("6Aoh8h2Lw2m5UGxYR8AdAL87jTWYeKoxM52mJRzfYwN"),CREATE_CPMM_POOL_PROGRAM:new f("DRaycpLY18LhpbydsBWbVJtxpNv9oXPgjRSfpF2bWpYb"),CREATE_CPMM_POOL_AUTH:new f("CXniRufdq5xL8t8jZAPxsPZDpuudwuJSPWnbcD5Y5Nxq"),CREATE_CPMM_POOL_FEE_ACC:new f("3oE58BKVt8KuYkGxx8zBojugnymWmBiyafWgMrnb6eYy"),LOCK_CPMM_PROGRAM:new f("DRay25Usp3YJAi7beckgpGUC7mGJ2cR1AVPxhYfwVCUX"),LOCK_CPMM_AUTH:new f("7qWVV8UY2bRJfDLP4s37YzBPKUkVB46DStYJBpYbQzu3"),UTIL1216:f.default,Router:new f("DRaybByLpbUL57LJARs3j8BitTxVfzBg351EaMr5UTCd"),FARM_PROGRAM_ID_V3:new f("DRayWyrLmEW5KEeqs8kdTMMaBabapqagaBC7KWpGtJeZ"),FARM_PROGRAM_ID_V5:new f("DRayiCGSZgku1GTK6rXD6mVDdingXy6APAH1R6R5L2LC"),FARM_PROGRAM_ID_V6:new f("DRayzbYakXs45ELHkzH6vC3fuhQqTAnv5A68gdFuvZyZ"),LAUNCHPAD_PROGRAM:new f("DRay6fNdQ5J82H7xV6uq2aV3mNrUZ1J4PgSKsWgptcm6"),LAUNCHPAD_AUTH:new f("5xqNaZXX5eUi4p5HU4oz9i5QnwRNT2y6oN7yyn4qENeq"),LAUNCHPAD_PLATFORM:an,LAUNCHPAD_CONFIG:un,FEE_DESTINATION_ID:new f("9y8ENuuZ3b19quffx9hQvRVygG5ky6snHfRvGpuSfeJy"),MODEL_DATA_PUBKEY:sn};import Qe from"bn.js";function Ye(t,e){if(t.isZero())return new Qe(0);let n=t.div(e);return n.isZero()?new Qe(1):t.mod(e).gt(new Qe(0))?n.add(new Qe(1)):n}import{PublicKey as ar,AddressLookupTableAccount as cn}from"@solana/web3.js";var ur={AcL1Vo8oy1ULiavEcjSUcwfBSForXMudcZvDZy5nzJkU:new cn({key:new ar("AcL1Vo8oy1ULiavEcjSUcwfBSForXMudcZvDZy5nzJkU"),state:cn.deserialize(Buffer.from("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","base64"))})};import{PublicKey as Ku,sendAndConfirmTransaction as Lu,SystemProgram as Fu,Transaction as Ou,TransactionMessage as vu,VersionedTransaction as Du}from"@solana/web3.js";import Vu from"axios";import mr from"bn.js";var fe=new mr(1e6);var pe=class{static getPoolInitPriceByPool({poolInfo:e,decimalA:n,decimalB:i}){throw Error()}static getPoolInitPriceByInit({a:e,b:n,decimalA:i,decimalB:r}){throw Error()}static getPoolPrice({poolInfo:e,decimalA:n,decimalB:i}){throw Error()}static getPoolEndPrice({supply:e,totalSell:n,totalLockedAmount:i,totalFundRaising:r,migrateFee:o,decimalA:s,decimalB:a}){throw Error()}static getPoolEndPriceReal({poolInfo:e,decimalA:n,decimalB:i}){throw Error()}static getInitParam({supply:e,totalFundRaising:n,totalSell:i,totalLockedAmount:r,migrateFee:o}){throw Error()}static buyExactIn({poolInfo:e,amount:n}){throw Error()}static buyExactOut({poolInfo:e,amount:n}){throw Error()}static sellExactIn({poolInfo:e,amount:n}){throw Error()}static sellExactOut({poolInfo:e,amount:n}){throw Error()}};import{PublicKey as mp}from"@solana/web3.js";import pp from"bn.js";import{AccountLayout as yp,createAssociatedTokenAccountIdempotentInstruction as wp,TOKEN_2022_PROGRAM_ID as Pp,TOKEN_PROGRAM_ID as Ap}from"@solana/spl-token";import{PublicKey as gc}from"@solana/web3.js";import{MintLayout as wc,TOKEN_PROGRAM_ID as Ac}from"@solana/spl-token";import{Keypair as Fd,PublicKey as Od,SystemProgram as vd,TransactionInstruction as Dd}from"@solana/web3.js";import Vd from"bn.js";import{ASSOCIATED_TOKEN_PROGRAM_ID as Gd,TOKEN_2022_PROGRAM_ID as Ud,TOKEN_PROGRAM_ID as Xd}from"@solana/spl-token";import{PublicKey as Ar}from"@solana/web3.js";import fn,{isBN as bn}from"bn.js";import{bits as Rc,BitStructure as Mc,blob as dr,Blob as Fc,cstr as Oc,f32 as Ec,f32be as vc,f64 as Dc,f64be as _c,greedy as Vc,Layout as pr,ns64 as Wc,ns64be as qc,nu64 as Gc,nu64be as Uc,offset as Xc,s16 as Hc,s16be as Zc,s24 as zc,s24be as jc,s32 as fr,s32be as Qc,s40 as Yc,s40be as Jc,s48 as $c,s48be as el,s8 as tl,seq as br,struct as nl,Structure as gr,u16 as yr,u16be as il,u24 as rl,u24be as ol,u32 as sl,u32be as al,u40 as ul,u40be as cl,u48 as ll,u48be as ml,u8 as wr,UInt as Pr,union as dl,Union as pl,unionLayoutDiscriminator as fl,utf8 as bl}from"@solana/buffer-layout";var Tt=pr,mn=gr;var kt=Pr;var dn=wr,Ne=yr;var se=fr;var pn=br;var Z=dr;var we=class extends Tt{constructor(n,i,r){super(n,r);this.blob=Z(n),this.signed=i}decode(n,i=0){let r=new fn(this.blob.decode(n,i),10,"le");return this.signed?r.fromTwos(this.span*8).clone():r}encode(n,i,r=0){return typeof n=="number"&&(n=new fn(n)),this.signed&&(n=n.toTwos(this.span*8)),this.blob.encode(n.toArrayLike(Buffer,"le",this.span),i,r)}};function G(t){return new kt(1,t)}function Pe(t){return new kt(4,t)}function k(t){return new we(8,!1,t)}function R(t){return new we(16,!1,t)}function gn(t){return new we(8,!0,t)}function yn(t){return new we(16,!0,t)}var Je=class extends Tt{constructor(n,i,r,o){super(n.span,o);this.layout=n,this.decoder=i,this.encoder=r}decode(n,i){return this.decoder(this.layout.decode(n,i))}encode(n,i,r){return this.layout.encode(this.encoder(n),i,r)}getSpan(n,i){return this.layout.getSpan(n,i)}};function S(t){return new Je(Z(32),e=>new Ar(e),e=>e.toBuffer(),t)}function xt(t){return new Je(dn(),hr,Tr,t)}function hr(t){if(t===0)return!1;if(t===1)return!0;throw new Error("Invalid bool: "+t)}function Tr(t){return t?1:0}var Bt=class extends mn{decode(e,n){return super.decode(e,n)}};function W(t,e,n){return new Bt(t,e,n)}function M(t,e,n){let i,r=typeof e=="number"?e:bn(e)?e.toNumber():new Proxy(e,{get(o,s){if(!i){let a=Reflect.get(o,"count");i=bn(a)?a.toNumber():a,Reflect.set(o,"count",i)}return Reflect.get(o,s)},set(o,s,a){return s==="count"&&(i=a),Reflect.set(o,s,a)}});return pn(t,r,n)}import pd from"bn.js";import Q from"bn.js";var It=new Q(0),wn=new Q(1),Pn=new Q(-1),ee=new Q(1).shln(64),An=new Q(1).shln(128),St=ee.sub(wn);var kr=An.subn(1),Ae=-443636,Ke=-Ae,Ct=new Q("4295048016"),Nt=new Q("79226673521066979257578248091"),Nl=new Q("4295048017"),Kl=new Q("79226673521066979257578248090");var Br=new Q(10).pow(new Q(6));var Ll=new Q("18446744073700000000");import $m from"bn.js";var Dl=Buffer.from("amm_config","utf8"),_l=Buffer.from("pool","utf8"),Vl=Buffer.from("pool_vault","utf8"),Wl=Buffer.from("pool_reward_vault","utf8"),ql=Buffer.from("position","utf8"),Gl=Buffer.from("tick_array","utf8"),Ul=Buffer.from("operation","utf8"),Xl=Buffer.from("pool_tick_array_bitmap_extension","utf8"),Hl=Buffer.from("observation","utf8");var Zl=Buffer.from("locked_position","utf8");var zl=Buffer.from("support_mint","utf8");import{PublicKey as Sm}from"@solana/web3.js";import{TOKEN_2022_PROGRAM_ID as Nm}from"@solana/spl-token";import Lm from"bn.js";import Yl from"bn.js";var Rt=14;var $e=60;var Nr=W([Z(8),G("bump"),Ne("index"),S(""),Pe("protocolFeeRate"),Pe("tradeFeeRate"),Ne("tickSpacing"),M(k(),8,"")]),Kr=W([Pe("blockTimestamp"),gn("tickCumulative"),M(k(),4)]),Kn=W([Z(8),xt("initialized"),k("recentEpoch"),Ne("observationIndex"),S("poolId"),M(Kr,100,"observations"),M(k(),4)]),Lr=W([G("rewardState"),k("openTime"),k("endTime"),k("lastUpdateTime"),R("emissionsPerSecondX64"),k("rewardTotalEmissioned"),k("rewardClaimed"),S("tokenMint"),S("tokenVault"),S("creator"),R("rewardGrowthGlobalX64")]),Sn=W([Z(8),G("bump"),S("ammConfig"),S("creator"),S("mintA"),S("mintB"),S("vaultA"),S("vaultB"),S("observationId"),G("mintDecimalsA"),G("mintDecimalsB"),Ne("tickSpacing"),R("liquidity"),R("sqrtPriceX64"),se("tickCurrent"),Pe(),R("feeGrowthGlobalX64A"),R("feeGrowthGlobalX64B"),k("protocolFeesTokenA"),k("protocolFeesTokenB"),R("swapInAmountTokenA"),R("swapOutAmountTokenB"),R("swapInAmountTokenB"),R("swapOutAmountTokenA"),G("status"),M(G(),7,""),M(Lr,3,"rewardInfos"),M(k(),16,"tickArrayBitmap"),k("totalFeesTokenA"),k("totalFeesClaimedTokenA"),k("totalFeesTokenB"),k("totalFeesClaimedTokenB"),k("fundFeesTokenA"),k("fundFeesTokenB"),k("startTime"),M(k(),15*4-3,"padding")]),Rr=W([R("growthInsideLastX64"),k("rewardAmountOwed")]),Cn=W([Z(8),G("bump"),S("nftMint"),S("poolId"),se("tickLower"),se("tickUpper"),R("liquidity"),R("feeGrowthInsideLastX64A"),R("feeGrowthInsideLastX64B"),k("tokenFeesOwedA"),k("tokenFeesOwedB"),M(Rr,3,"rewardInfos"),M(k(),8,"")]),kd=W([Z(8),G("bump"),S("poolId"),se("tickLowerIndex"),se("tickUpperIndex"),R("liquidity"),R("feeGrowthInsideLastX64A"),R("feeGrowthInsideLastX64B"),k("tokenFeesOwedA"),k("tokenFeesOwedB"),M(R(),3,"rewardGrowthInside"),M(k(),8,"")]),Mr=W([se("tick"),yn("liquidityNet"),R("liquidityGross"),R("feeGrowthOutsideX64A"),R("feeGrowthOutsideX64B"),M(R(),3,"rewardGrowthsOutsideX64"),M(Pe(),13,"")]),Bn=W([Z(8),S("poolId"),se("startTickIndex"),M(Mr,$e,"ticks"),G("initializedTickCount"),M(G(),115,"")]),Fr=W([Z(329),M(S(),100,"whitelistMints")]),Cr=W([Z(8),S("poolId"),M(M(k(),8),Rt,"positiveTickArrayBitmap"),M(M(k(),8),Rt,"negativeTickArrayBitmap")]),Bd=W([k(),G("bump"),S("owner"),S("poolId"),S("positionId"),S("nftAccount"),M(k(),8)]),Or=W([Z(8),G("bump"),S("lockOwner"),S("poolId"),S("positionId"),S("nftAccount"),S("lockNftMint"),k("recentEpoch"),M(k(),8)]);Kn.span;var ep=q("Raydium_Clmm");var et=class extends pe{static getPoolInitPriceByPool({poolInfo:e,decimalA:n,decimalB:i}){return new x(e.virtualB.toString()).div(e.virtualA.toString()).mul(10**(n-i))}static getPoolInitPriceByInit({a:e,b:n,decimalA:i,decimalB:r}){return new x(n.toString()).div(e.toString()).mul(10**(i-r))}static getPoolPrice({poolInfo:e,decimalA:n,decimalB:i}){return new x(e.virtualB.add(e.realB).toString()).div(e.virtualA.sub(e.realA).toString()).mul(10**(n-i))}static getPoolEndPrice({supply:e,totalSell:n,totalLockedAmount:i,totalFundRaising:r,migrateFee:o,decimalA:s,decimalB:a}){return new x(r.sub(o).toString()).div(e.sub(n).sub(i).toString()).mul(10**(s-a))}static getPoolEndPriceReal({poolInfo:e,decimalA:n,decimalB:i}){let r=e.totalSellA.sub(e.realA),o=e.totalFundRaisingB.sub(e.realB);return new x(e.virtualB.add(e.realB.add(o)).toString()).div(e.virtualA.sub(e.realA.add(r)).toString()).mul(10**(n-i))}static getInitParam({supply:e,totalFundRaising:n,totalSell:i,totalLockedAmount:r,migrateFee:o}){if(e.lte(i))throw Error("supply need gt total sell");let s=e.sub(i).sub(r);if(s.lte(new Me(0)))throw Error("supplyMinusSellLocked <= 0");let a=n.sub(o);if(a.lte(new Me(0)))throw Error("tfMinusMf <= 0");let c=a.mul(i).mul(i).div(s),u=a.mul(i).div(s).sub(n);if(u.lt(new Me(0)))throw Error("supply/totalSell/totalLockedAmount diff too high");let l=c.div(u),m=n.mul(n).div(u);if(l.lt(new Me(0))||m.lt(new Me(0)))throw Error("invalid input 0");return{a:l,b:m,c:i}}static buyExactIn({poolInfo:e,amount:n}){return this.getAmountOut({amountIn:n,inputReserve:e.virtualB.add(e.realB),outputReserve:e.virtualA.sub(e.realA)})}static buyExactOut({poolInfo:e,amount:n}){return this.getAmountIn({amountOut:n,inputReserve:e.virtualB.add(e.realB),outputReserve:e.virtualA.sub(e.realA)})}static sellExactIn({poolInfo:e,amount:n}){return this.getAmountOut({amountIn:n,inputReserve:e.virtualA.sub(e.realA),outputReserve:e.virtualB.add(e.realB)})}static sellExactOut({poolInfo:e,amount:n}){return this.getAmountIn({amountOut:n,inputReserve:e.virtualA.sub(e.realA),outputReserve:e.virtualB.add(e.realB)})}static getAmountOut({amountIn:e,inputReserve:n,outputReserve:i}){let r=e.mul(i),o=n.add(e);return r.div(o)}static getAmountIn({amountOut:e,inputReserve:n,outputReserve:i}){let r=n.mul(e),o=i.sub(e);return Ye(r,o)}};import Ln from"bn.js";var tt=class extends pe{static getPoolInitPriceByPool({poolInfo:e,decimalA:n,decimalB:i}){return new x(e.virtualB.toString()).div(e.virtualA.toString()).mul(10**(n-i))}static getPoolInitPriceByInit({a:e,b:n,decimalA:i,decimalB:r}){return new x(n.toString()).div(e.toString()).mul(10**(i-r))}static getPoolPrice({poolInfo:e,decimalA:n,decimalB:i}){return new x(e.virtualB.toString()).div(e.virtualA.toString()).mul(10**(n-i))}static getPoolEndPrice({supply:e,totalSell:n,totalLockedAmount:i,totalFundRaising:r,migrateFee:o,decimalA:s,decimalB:a}){return new x(r.sub(o).toString()).div(e.sub(n).sub(i).toString()).mul(10**(s-a))}static getPoolEndPriceReal({poolInfo:e,decimalA:n,decimalB:i}){let r=e.totalSellA.sub(e.realA),o=e.totalFundRaisingB.sub(e.realB);return new x(e.virtualB.add(e.realB).add(o).toString()).div(e.virtualA.sub(e.realA).add(r).toString()).mul(10**(n-i))}static getInitParam({supply:e,totalFundRaising:n,totalSell:i,totalLockedAmount:r,migrateFee:o}){let s=e.sub(r);if(s.lte(new Ln(0)))throw Error("invalid input 1");let a=new Ln(2).mul(n).sub(o),u=n.mul(s).div(a);return{a:u,b:n,c:u}}static buyExactIn({poolInfo:e,amount:n}){return this.getAmountOut({amountIn:n,initInput:e.virtualB,initOutput:e.virtualA})}static buyExactOut({poolInfo:e,amount:n}){return this.getAmountIn({amountOut:n,initInput:e.virtualB,initOutput:e.virtualA})}static sellExactIn({poolInfo:e,amount:n}){return this.getAmountOut({amountIn:n,initInput:e.virtualA,initOutput:e.virtualB})}static sellExactOut({poolInfo:e,amount:n}){return this.getAmountIn({amountOut:n,initInput:e.virtualA,initOutput:e.virtualB})}static getAmountOut({amountIn:e,initInput:n,initOutput:i}){return i.mul(e).div(n)}static getAmountIn({amountOut:e,initInput:n,initOutput:i}){let r=n.mul(e);return Ye(r,i)}};import X from"bn.js";import Rn from"bn.js";var Fe=class{static _multipler(e){return new x(10).pow(e)}static getPrice({priceX64:e,decimalA:n,decimalB:i}){return new x(e.toString()).div(this._Q64).mul(this._multipler(n)).div(this._multipler(i))}static getPriceX64({price:e,decimalA:n,decimalB:i}){let r=e.mul(this._multipler(i)).div(this._multipler(n));return new Rn(r.mul(this._Q64).toFixed(0))}};Fe._Q64=new x(new Rn(1).shln(64).toString());var nt=class extends pe{static getPoolInitPriceByPool({poolInfo:e,decimalA:n,decimalB:i}){return new x(0)}static getPoolInitPriceByInit({a:e,b:n,decimalA:i,decimalB:r}){return new x(0)}static getPoolPrice({poolInfo:e,decimalA:n,decimalB:i}){return new x(e.virtualA.mul(e.realA).toString()).div(Fe._Q64).mul(10**(n-i))}static getPoolEndPrice({supply:e,totalSell:n,totalLockedAmount:i,totalFundRaising:r,migrateFee:o,decimalA:s,decimalB:a}){return new x(r.sub(o).toString()).div(e.sub(n).sub(i).toString()).mul(10**(s-a))}static getPoolEndPriceReal({poolInfo:e,decimalA:n,decimalB:i}){let r=e.totalSellA.sub(e.realA),o=e.totalFundRaisingB.sub(e.realB);return new x(e.virtualB.add(e.realB).add(o).toString()).div(e.virtualA.sub(e.realA).add(r).toString()).mul(10**(n-i))}static getInitParam({supply:e,totalFundRaising:n,totalSell:i,totalLockedAmount:r,migrateFee:o}){let s=e.sub(r);if(s.lte(new X(0)))throw Error("supplyMinusLocked need gt 0");let a=n.mul(new X(3)).sub(o),u=n.mul(new X(2)).mul(s).div(a),l=u.mul(u),m=n.mul(new X(2)).mul(ee).div(l);if(!m.gt(new X(0)))throw Error("a need gt 0");if(!St.gt(m))throw Error("a need lt u64 max");return{a:m,b:new X(0),c:u}}static buyExactIn({poolInfo:e,amount:n}){let i=e.realB.add(n),r=new X(2).mul(i).mul(ee).div(e.virtualA);return new X(new x(r.toString()).sqrt().toFixed(0)).sub(e.realA)}static buyExactOut({poolInfo:e,amount:n}){let i=e.realA.add(n),r=i.mul(i),{div:o,mod:s}=e.virtualA.mul(r).divmod(new X(2).mul(ee));return(s.isZero()?o:o.add(new X(1))).sub(e.realB)}static sellExactIn({poolInfo:e,amount:n}){let i=e.realA.sub(n),r=i.mul(i),{div:o,mod:s}=e.virtualA.mul(r).divmod(new X(2).mul(ee)),a=s.isZero()?o:o.add(new X(1));return e.realB.sub(a)}static sellExactOut({poolInfo:e,amount:n}){let i=e.realB.sub(n),r=new X(2).mul(i).mul(ee).div(e.virtualA),o=new X(new x(r.toString()).sqrt().toFixed(0));return e.realA.sub(o)}};var it=class{static getPoolCurvePointByPoolInfo({curveType:e,pointCount:n,poolInfo:i}){return this.getPoolCurvePointByInit({curveType:e,pointCount:n,supply:i.supply,totalFundRaising:i.totalFundRaisingB,totalSell:i.totalSellA,totalLockedAmount:i.vestingSchedule.totalLockedAmount,migrateFee:i.migrateFee,decimalA:i.mintDecimalsA,decimalB:i.mintDecimalsB})}static getPoolCurvePointByInit({curveType:e,pointCount:n,supply:i,totalFundRaising:r,totalSell:o,totalLockedAmount:s,migrateFee:a,decimalA:c,decimalB:u}){if(n<3)throw Error("point count < 3");let l=this.getCurve(e),m=l.getInitParam({supply:i,totalFundRaising:r,totalSell:o,totalLockedAmount:s,migrateFee:a}),d=l.getPoolInitPriceByInit(j(H({},m),{decimalA:c,decimalB:u})),b=r.div(new re(n-1)),h=new re(0),P=[{price:d,totalSellSupply:0}],{a:F,b:I}=m,v=h,B=h;for(let O=1;O<n;O++){let be=O!==n-1?b:r.sub(B),z=this.buyExactIn({poolInfo:{virtualA:F,virtualB:I,realA:v,realB:B,totalFundRaisingB:r,totalSellA:o},amountB:be,protocolFeeRate:h,platformFeeRate:h,curveType:e,shareFeeRate:h});v=v.add(z.amountA),B=B.add(z.amountB);let he=this.getPrice({poolInfo:{virtualA:F,virtualB:I,realA:v,realB:B},decimalA:c,decimalB:u,curveType:e});P.push({price:he,totalSellSupply:new x(v.toString()).div(10**c).toNumber()})}return P}static getPoolInitPriceByPool({poolInfo:e,decimalA:n,decimalB:i,curveType:r}){return this.getCurve(r).getPoolInitPriceByPool({poolInfo:e,decimalA:n,decimalB:i})}static getPoolInitPriceByInit({a:e,b:n,decimalA:i,decimalB:r,curveType:o}){return this.getCurve(o).getPoolInitPriceByInit({a:e,b:n,decimalA:i,decimalB:r})}static getPrice({poolInfo:e,curveType:n,decimalA:i,decimalB:r}){return this.getCurve(n).getPoolPrice({poolInfo:e,decimalA:i,decimalB:r})}static getEndPrice({poolInfo:e,curveType:n,decimalA:i,decimalB:r}){return this.getCurve(n).getPoolPrice({poolInfo:e,decimalA:i,decimalB:r})}static getPoolEndPriceReal({poolInfo:e,curveType:n,decimalA:i,decimalB:r}){return this.getCurve(n).getPoolEndPriceReal({poolInfo:e,decimalA:i,decimalB:r})}static checkParam({supply:e,totalFundRaising:n,totalSell:i,totalLockedAmount:r,decimals:o,config:s,migrateType:a}){if(Number(o)!==6)throw Error("decimals = 6");if(e.mul(s.maxLockRate).div(fe).lt(r))throw Error("total lock amount gte max lock amount");if(e.lt(s.minSupplyA.mul(new re(10**o))))throw Error("supply lt min supply");let u=e.mul(s.minSellRateA).div(fe);if(i.lt(u))throw Error("invalid input");if(n.lt(s.minFundRaisingB))throw Error("total fund raising lt min fund raising");let l=e.sub(i).sub(r),m=e.mul(s.minMigrateRateA).div(fe);if(l.lt(m))throw Error("migrate lt min migrate amount");let d=e.sub(i).sub(r),b=new re(new x(d.mul(n).toString()).sqrt().toFixed(0));if(a==="amm"){let h=new re(10).pow(new re(o));if(b.lte(h))throw Error("check migrate lp error")}else if(a==="cpmm"){let h=new re(100);if(b.lte(h))throw Error("check migrate lp error")}else throw Error("migrate type error")}static buyExactIn({poolInfo:e,amountB:n,protocolFeeRate:i,platformFeeRate:r,curveType:o,shareFeeRate:s}){let a=i.add(s).add(r),c=this.calculateFee({amount:n,feeRate:a}),u=n.sub(c),l=this.getCurve(o),m=l.buyExactIn({poolInfo:e,amount:u}),d=e.totalSellA.sub(e.realA),b,h,P;if(m.gt(d)){b=d;let I=l.buyExactOut({poolInfo:e,amount:b});h=this.calculatePreFee({postFeeAmount:I,feeRate:a}),P=h.sub(I)}else b=m,h=n,P=c;let F=this.splitFee({totalFee:P,protocolFeeRate:i,platformFeeRate:r,shareFeeRate:s});return{amountA:b,amountB:h,splitFee:F}}static buyExactOut({poolInfo:e,amountA:n,protocolFeeRate:i,platformFeeRate:r,curveType:o,shareFeeRate:s}){let a=e.totalSellA.sub(e.realA),c=n;n.gt(a)&&(c=a);let l=this.getCurve(o).buyExactOut({poolInfo:e,amount:n}),m=i.add(s).add(r),d=this.calculatePreFee({postFeeAmount:l,feeRate:m}),b=d.sub(l),h=this.splitFee({totalFee:b,protocolFeeRate:i,platformFeeRate:r,shareFeeRate:s});return{amountA:c,amountB:d,splitFee:h}}static sellExactIn({poolInfo:e,amountA:n,protocolFeeRate:i,platformFeeRate:r,curveType:o,shareFeeRate:s}){let c=this.getCurve(o).sellExactIn({poolInfo:e,amount:n}),u=this.calculateFee({amount:c,feeRate:i.add(s).add(r)}),l=this.splitFee({totalFee:u,protocolFeeRate:i,platformFeeRate:r,shareFeeRate:s});return{amountA:n,amountB:c.sub(u),splitFee:l}}static sellExactOut({poolInfo:e,amountB:n,protocolFeeRate:i,platformFeeRate:r,curveType:o,shareFeeRate:s}){let a=i.add(s).add(r),c=this.calculatePreFee({postFeeAmount:n,feeRate:a});if(e.realB.lt(c))throw Error("Insufficient liquidity");let u=c.sub(n),m=it.getCurve(o).sellExactOut({poolInfo:e,amount:c});if(m.gt(e.realA))throw Error();let d=this.splitFee({totalFee:u,protocolFeeRate:i,platformFeeRate:r,shareFeeRate:s});return{amountA:m,amountB:n,splitFee:d}}static splitFee({totalFee:e,protocolFeeRate:n,platformFeeRate:i,shareFeeRate:r}){let o=n.add(i).add(r),s=o.isZero()?new re(0):e.mul(i).div(o),a=o.isZero()?new re(0):e.mul(r).div(o),c=e.sub(s).sub(a);return{platformFee:s,shareFee:a,protocolFee:c}}static calculateFee({amount:e,feeRate:n}){return on(e,n,fe)}static calculatePreFee({postFeeAmount:e,feeRate:n}){if(n.isZero())return e;let i=e.mul(fe),r=fe.sub(n);return i.add(r).sub(new re(1)).div(r)}static getCurve(e){switch(e){case 0:return et;case 1:return tt;case 2:return nt}throw Error("find curve error")}};export{it as Curve};
1
+ var Mn=Object.defineProperty,Fn=Object.defineProperties;var On=Object.getOwnPropertyDescriptors;var Mt=Object.getOwnPropertySymbols;var En=Object.prototype.hasOwnProperty,vn=Object.prototype.propertyIsEnumerable;var Ft=(t,e,n)=>e in t?Mn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,H=(t,e)=>{for(var n in e||(e={}))En.call(e,n)&&Ft(t,n,e[n]);if(Mt)for(var n of Mt(e))vn.call(e,n)&&Ft(t,n,e[n]);return t},j=(t,e)=>Fn(t,On(e));import re from"bn.js";import Me from"bn.js";var ge=9e15,le=1e9,st="0123456789abcdef",_e="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Ve="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",at={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-ge,maxE:ge,crypto:!1},Dt,oe,k=!0,qe="[DecimalError] ",ce=qe+"Invalid argument: ",_t=qe+"Precision limit exceeded",Vt=qe+"crypto unavailable",Wt="[object Decimal]",V=Math.floor,E=Math.pow,Dn=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,_n=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Vn=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,qt=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,$=1e7,A=7,Wn=9007199254740991,qn=_e.length-1,ut=Ve.length-1,p={toStringTag:Wt};p.absoluteValue=p.abs=function(){var t=new this.constructor(this);return t.s<0&&(t.s=1),g(t)};p.ceil=function(){return g(new this.constructor(this),this.e+1,2)};p.clampedTo=p.clamp=function(t,e){var n,i=this,r=i.constructor;if(t=new r(t),e=new r(e),!t.s||!e.s)return new r(NaN);if(t.gt(e))throw Error(ce+e);return n=i.cmp(t),n<0?t:i.cmp(e)>0?e:new r(i)};p.comparedTo=p.cmp=function(t){var e,n,i,r,o=this,s=o.d,a=(t=new o.constructor(t)).d,c=o.s,u=t.s;if(!s||!a)return!c||!u?NaN:c!==u?c:s===a?0:!s^c<0?1:-1;if(!s[0]||!a[0])return s[0]?c:a[0]?-u:0;if(c!==u)return c;if(o.e!==t.e)return o.e>t.e^c<0?1:-1;for(i=s.length,r=a.length,e=0,n=i<r?i:r;e<n;++e)if(s[e]!==a[e])return s[e]>a[e]^c<0?1:-1;return i===r?0:i>r^c<0?1:-1};p.cosine=p.cos=function(){var t,e,n=this,i=n.constructor;return n.d?n.d[0]?(t=i.precision,e=i.rounding,i.precision=t+Math.max(n.e,n.sd())+A,i.rounding=1,n=Gn(i,Zt(i,n)),i.precision=t,i.rounding=e,g(oe==2||oe==3?n.neg():n,t,e,!0)):new i(1):new i(NaN)};p.cubeRoot=p.cbrt=function(){var t,e,n,i,r,o,s,a,c,u,l=this,m=l.constructor;if(!l.isFinite()||l.isZero())return new m(l);for(k=!1,o=l.s*E(l.s*l,1/3),!o||Math.abs(o)==1/0?(n=D(l.d),t=l.e,(o=(t-n.length+1)%3)&&(n+=o==1||o==-2?"0":"00"),o=E(n,1/3),t=V((t+1)/3)-(t%3==(t<0?-1:2)),o==1/0?n="5e"+t:(n=o.toExponential(),n=n.slice(0,n.indexOf("e")+1)+t),i=new m(n),i.s=l.s):i=new m(o.toString()),s=(t=m.precision)+3;;)if(a=i,c=a.times(a).times(a),u=c.plus(l),i=C(u.plus(l).times(a),u.plus(c),s+2,1),D(a.d).slice(0,s)===(n=D(i.d)).slice(0,s))if(n=n.slice(s-3,s+1),n=="9999"||!r&&n=="4999"){if(!r&&(g(a,t+1,0),a.times(a).times(a).eq(l))){i=a;break}s+=4,r=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(g(i,t+1,1),e=!i.times(i).times(i).eq(l));break}return k=!0,g(i,t,m.rounding,e)};p.decimalPlaces=p.dp=function(){var t,e=this.d,n=NaN;if(e){if(t=e.length-1,n=(t-V(this.e/A))*A,t=e[t],t)for(;t%10==0;t/=10)n--;n<0&&(n=0)}return n};p.dividedBy=p.div=function(t){return C(this,new this.constructor(t))};p.dividedToIntegerBy=p.divToInt=function(t){var e=this,n=e.constructor;return g(C(e,new n(t),0,1,1),n.precision,n.rounding)};p.equals=p.eq=function(t){return this.cmp(t)===0};p.floor=function(){return g(new this.constructor(this),this.e+1,3)};p.greaterThan=p.gt=function(t){return this.cmp(t)>0};p.greaterThanOrEqualTo=p.gte=function(t){var e=this.cmp(t);return e==1||e===0};p.hyperbolicCosine=p.cosh=function(){var t,e,n,i,r,o=this,s=o.constructor,a=new s(1);if(!o.isFinite())return new s(o.s?1/0:NaN);if(o.isZero())return a;n=s.precision,i=s.rounding,s.precision=n+Math.max(o.e,o.sd())+4,s.rounding=1,r=o.d.length,r<32?(t=Math.ceil(r/3),e=(1/Ue(4,t)).toString()):(t=16,e="2.3283064365386962890625e-10"),o=ye(s,1,o.times(e),new s(1),!0);for(var c,u=t,l=new s(8);u--;)c=o.times(o),o=a.minus(c.times(l.minus(c.times(l))));return g(o,s.precision=n,s.rounding=i,!0)};p.hyperbolicSine=p.sinh=function(){var t,e,n,i,r=this,o=r.constructor;if(!r.isFinite()||r.isZero())return new o(r);if(e=o.precision,n=o.rounding,o.precision=e+Math.max(r.e,r.sd())+4,o.rounding=1,i=r.d.length,i<3)r=ye(o,2,r,r,!0);else{t=1.4*Math.sqrt(i),t=t>16?16:t|0,r=r.times(1/Ue(5,t)),r=ye(o,2,r,r,!0);for(var s,a=new o(5),c=new o(16),u=new o(20);t--;)s=r.times(r),r=r.times(a.plus(s.times(c.times(s).plus(u))))}return o.precision=e,o.rounding=n,g(r,e,n,!0)};p.hyperbolicTangent=p.tanh=function(){var t,e,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(t=i.precision,e=i.rounding,i.precision=t+7,i.rounding=1,C(n.sinh(),n.cosh(),i.precision=t,i.rounding=e)):new i(n.s)};p.inverseCosine=p.acos=function(){var t,e=this,n=e.constructor,i=e.abs().cmp(1),r=n.precision,o=n.rounding;return i!==-1?i===0?e.isNeg()?J(n,r,o):new n(0):new n(NaN):e.isZero()?J(n,r+4,o).times(.5):(n.precision=r+6,n.rounding=1,e=e.asin(),t=J(n,r+4,o).times(.5),n.precision=r,n.rounding=o,t.minus(e))};p.inverseHyperbolicCosine=p.acosh=function(){var t,e,n=this,i=n.constructor;return n.lte(1)?new i(n.eq(1)?0:NaN):n.isFinite()?(t=i.precision,e=i.rounding,i.precision=t+Math.max(Math.abs(n.e),n.sd())+4,i.rounding=1,k=!1,n=n.times(n).minus(1).sqrt().plus(n),k=!0,i.precision=t,i.rounding=e,n.ln()):new i(n)};p.inverseHyperbolicSine=p.asinh=function(){var t,e,n=this,i=n.constructor;return!n.isFinite()||n.isZero()?new i(n):(t=i.precision,e=i.rounding,i.precision=t+2*Math.max(Math.abs(n.e),n.sd())+6,i.rounding=1,k=!1,n=n.times(n).plus(1).sqrt().plus(n),k=!0,i.precision=t,i.rounding=e,n.ln())};p.inverseHyperbolicTangent=p.atanh=function(){var t,e,n,i,r=this,o=r.constructor;return r.isFinite()?r.e>=0?new o(r.abs().eq(1)?r.s/0:r.isZero()?r:NaN):(t=o.precision,e=o.rounding,i=r.sd(),Math.max(i,t)<2*-r.e-1?g(new o(r),t,e,!0):(o.precision=n=i-r.e,r=C(r.plus(1),new o(1).minus(r),n+t,1),o.precision=t+4,o.rounding=1,r=r.ln(),o.precision=t,o.rounding=e,r.times(.5))):new o(NaN)};p.inverseSine=p.asin=function(){var t,e,n,i,r=this,o=r.constructor;return r.isZero()?new o(r):(e=r.abs().cmp(1),n=o.precision,i=o.rounding,e!==-1?e===0?(t=J(o,n+4,i).times(.5),t.s=r.s,t):new o(NaN):(o.precision=n+6,o.rounding=1,r=r.div(new o(1).minus(r.times(r)).sqrt().plus(1)).atan(),o.precision=n,o.rounding=i,r.times(2)))};p.inverseTangent=p.atan=function(){var t,e,n,i,r,o,s,a,c,u=this,l=u.constructor,m=l.precision,d=l.rounding;if(u.isFinite()){if(u.isZero())return new l(u);if(u.abs().eq(1)&&m+4<=ut)return s=J(l,m+4,d).times(.25),s.s=u.s,s}else{if(!u.s)return new l(NaN);if(m+4<=ut)return s=J(l,m+4,d).times(.5),s.s=u.s,s}for(l.precision=a=m+10,l.rounding=1,n=Math.min(28,a/A+2|0),t=n;t;--t)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(k=!1,e=Math.ceil(a/A),i=1,c=u.times(u),s=new l(u),r=u;t!==-1;)if(r=r.times(c),o=s.minus(r.div(i+=2)),r=r.times(c),s=o.plus(r.div(i+=2)),s.d[e]!==void 0)for(t=e;s.d[t]===o.d[t]&&t--;);return n&&(s=s.times(2<<n-1)),k=!0,g(s,l.precision=m,l.rounding=d,!0)};p.isFinite=function(){return!!this.d};p.isInteger=p.isInt=function(){return!!this.d&&V(this.e/A)>this.d.length-2};p.isNaN=function(){return!this.s};p.isNegative=p.isNeg=function(){return this.s<0};p.isPositive=p.isPos=function(){return this.s>0};p.isZero=function(){return!!this.d&&this.d[0]===0};p.lessThan=p.lt=function(t){return this.cmp(t)<0};p.lessThanOrEqualTo=p.lte=function(t){return this.cmp(t)<1};p.logarithm=p.log=function(t){var e,n,i,r,o,s,a,c,u=this,l=u.constructor,m=l.precision,d=l.rounding,b=5;if(t==null)t=new l(10),e=!0;else{if(t=new l(t),n=t.d,t.s<0||!n||!n[0]||t.eq(1))return new l(NaN);e=t.eq(10)}if(n=u.d,u.s<0||!n||!n[0]||u.eq(1))return new l(n&&!n[0]?-1/0:u.s!=1?NaN:n?0:1/0);if(e)if(n.length>1)o=!0;else{for(r=n[0];r%10===0;)r/=10;o=r!==1}if(k=!1,a=m+b,s=ue(u,a),i=e?We(l,a+10):ue(t,a),c=C(s,i,a,1),Te(c.d,r=m,d))do if(a+=10,s=ue(u,a),i=e?We(l,a+10):ue(t,a),c=C(s,i,a,1),!o){+D(c.d).slice(r+1,r+15)+1==1e14&&(c=g(c,m+1,0));break}while(Te(c.d,r+=10,d));return k=!0,g(c,m,d)};p.minus=p.sub=function(t){var e,n,i,r,o,s,a,c,u,l,m,d,b=this,h=b.constructor;if(t=new h(t),!b.d||!t.d)return!b.s||!t.s?t=new h(NaN):b.d?t.s=-t.s:t=new h(t.d||b.s!==t.s?b:NaN),t;if(b.s!=t.s)return t.s=-t.s,b.plus(t);if(u=b.d,d=t.d,a=h.precision,c=h.rounding,!u[0]||!d[0]){if(d[0])t.s=-t.s;else if(u[0])t=new h(b);else return new h(c===3?-0:0);return k?g(t,a,c):t}if(n=V(t.e/A),l=V(b.e/A),u=u.slice(),o=l-n,o){for(m=o<0,m?(e=u,o=-o,s=d.length):(e=d,n=l,s=u.length),i=Math.max(Math.ceil(a/A),s)+2,o>i&&(o=i,e.length=1),e.reverse(),i=o;i--;)e.push(0);e.reverse()}else{for(i=u.length,s=d.length,m=i<s,m&&(s=i),i=0;i<s;i++)if(u[i]!=d[i]){m=u[i]<d[i];break}o=0}for(m&&(e=u,u=d,d=e,t.s=-t.s),s=u.length,i=d.length-s;i>0;--i)u[s++]=0;for(i=d.length;i>o;){if(u[--i]<d[i]){for(r=i;r&&u[--r]===0;)u[r]=$-1;--u[r],u[i]+=$}u[i]-=d[i]}for(;u[--s]===0;)u.pop();for(;u[0]===0;u.shift())--n;return u[0]?(t.d=u,t.e=Ge(u,n),k?g(t,a,c):t):new h(c===3?-0:0)};p.modulo=p.mod=function(t){var e,n=this,i=n.constructor;return t=new i(t),!n.d||!t.s||t.d&&!t.d[0]?new i(NaN):!t.d||n.d&&!n.d[0]?g(new i(n),i.precision,i.rounding):(k=!1,i.modulo==9?(e=C(n,t.abs(),0,3,1),e.s*=t.s):e=C(n,t,0,i.modulo,1),e=e.times(t),k=!0,n.minus(e))};p.naturalExponential=p.exp=function(){return ct(this)};p.naturalLogarithm=p.ln=function(){return ue(this)};p.negated=p.neg=function(){var t=new this.constructor(this);return t.s=-t.s,g(t)};p.plus=p.add=function(t){var e,n,i,r,o,s,a,c,u,l,m=this,d=m.constructor;if(t=new d(t),!m.d||!t.d)return!m.s||!t.s?t=new d(NaN):m.d||(t=new d(t.d||m.s===t.s?m:NaN)),t;if(m.s!=t.s)return t.s=-t.s,m.minus(t);if(u=m.d,l=t.d,a=d.precision,c=d.rounding,!u[0]||!l[0])return l[0]||(t=new d(m)),k?g(t,a,c):t;if(o=V(m.e/A),i=V(t.e/A),u=u.slice(),r=o-i,r){for(r<0?(n=u,r=-r,s=l.length):(n=l,i=o,s=u.length),o=Math.ceil(a/A),s=o>s?o+1:s+1,r>s&&(r=s,n.length=1),n.reverse();r--;)n.push(0);n.reverse()}for(s=u.length,r=l.length,s-r<0&&(r=s,n=l,l=u,u=n),e=0;r;)e=(u[--r]=u[r]+l[r]+e)/$|0,u[r]%=$;for(e&&(u.unshift(e),++i),s=u.length;u[--s]==0;)u.pop();return t.d=u,t.e=Ge(u,i),k?g(t,a,c):t};p.precision=p.sd=function(t){var e,n=this;if(t!==void 0&&t!==!!t&&t!==1&&t!==0)throw Error(ce+t);return n.d?(e=Gt(n.d),t&&n.e+1>e&&(e=n.e+1)):e=NaN,e};p.round=function(){var t=this,e=t.constructor;return g(new e(t),t.e+1,e.rounding)};p.sine=p.sin=function(){var t,e,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(t=i.precision,e=i.rounding,i.precision=t+Math.max(n.e,n.sd())+A,i.rounding=1,n=Xn(i,Zt(i,n)),i.precision=t,i.rounding=e,g(oe>2?n.neg():n,t,e,!0)):new i(NaN)};p.squareRoot=p.sqrt=function(){var t,e,n,i,r,o,s=this,a=s.d,c=s.e,u=s.s,l=s.constructor;if(u!==1||!a||!a[0])return new l(!u||u<0&&(!a||a[0])?NaN:a?s:1/0);for(k=!1,u=Math.sqrt(+s),u==0||u==1/0?(e=D(a),(e.length+c)%2==0&&(e+="0"),u=Math.sqrt(e),c=V((c+1)/2)-(c<0||c%2),u==1/0?e="5e"+c:(e=u.toExponential(),e=e.slice(0,e.indexOf("e")+1)+c),i=new l(e)):i=new l(u.toString()),n=(c=l.precision)+3;;)if(o=i,i=o.plus(C(s,o,n+2,1)).times(.5),D(o.d).slice(0,n)===(e=D(i.d)).slice(0,n))if(e=e.slice(n-3,n+1),e=="9999"||!r&&e=="4999"){if(!r&&(g(o,c+1,0),o.times(o).eq(s))){i=o;break}n+=4,r=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(g(i,c+1,1),t=!i.times(i).eq(s));break}return k=!0,g(i,c,l.rounding,t)};p.tangent=p.tan=function(){var t,e,n=this,i=n.constructor;return n.isFinite()?n.isZero()?new i(n):(t=i.precision,e=i.rounding,i.precision=t+10,i.rounding=1,n=n.sin(),n.s=1,n=C(n,new i(1).minus(n.times(n)).sqrt(),t+10,0),i.precision=t,i.rounding=e,g(oe==2||oe==4?n.neg():n,t,e,!0)):new i(NaN)};p.times=p.mul=function(t){var e,n,i,r,o,s,a,c,u,l=this,m=l.constructor,d=l.d,b=(t=new m(t)).d;if(t.s*=l.s,!d||!d[0]||!b||!b[0])return new m(!t.s||d&&!d[0]&&!b||b&&!b[0]&&!d?NaN:!d||!b?t.s/0:t.s*0);for(n=V(l.e/A)+V(t.e/A),c=d.length,u=b.length,c<u&&(o=d,d=b,b=o,s=c,c=u,u=s),o=[],s=c+u,i=s;i--;)o.push(0);for(i=u;--i>=0;){for(e=0,r=c+i;r>i;)a=o[r]+b[i]*d[r-i-1]+e,o[r--]=a%$|0,e=a/$|0;o[r]=(o[r]+e)%$|0}for(;!o[--s];)o.pop();return e?++n:o.shift(),t.d=o,t.e=Ge(o,n),k?g(t,m.precision,m.rounding):t};p.toBinary=function(t,e){return mt(this,2,t,e)};p.toDecimalPlaces=p.toDP=function(t,e){var n=this,i=n.constructor;return n=new i(n),t===void 0?n:(U(t,0,le),e===void 0?e=i.rounding:U(e,0,8),g(n,t+n.e+1,e))};p.toExponential=function(t,e){var n,i=this,r=i.constructor;return t===void 0?n=te(i,!0):(U(t,0,le),e===void 0?e=r.rounding:U(e,0,8),i=g(new r(i),t+1,e),n=te(i,!0,t+1)),i.isNeg()&&!i.isZero()?"-"+n:n};p.toFixed=function(t,e){var n,i,r=this,o=r.constructor;return t===void 0?n=te(r):(U(t,0,le),e===void 0?e=o.rounding:U(e,0,8),i=g(new o(r),t+r.e+1,e),n=te(i,!1,t+i.e+1)),r.isNeg()&&!r.isZero()?"-"+n:n};p.toFraction=function(t){var e,n,i,r,o,s,a,c,u,l,m,d,b=this,h=b.d,P=b.constructor;if(!h)return new P(b);if(u=n=new P(1),i=c=new P(0),e=new P(i),o=e.e=Gt(h)-b.e-1,s=o%A,e.d[0]=E(10,s<0?A+s:s),t==null)t=o>0?e:u;else{if(a=new P(t),!a.isInt()||a.lt(u))throw Error(ce+a);t=a.gt(e)?o>0?e:u:a}for(k=!1,a=new P(D(h)),l=P.precision,P.precision=o=h.length*A*2;m=C(a,e,0,1,1),r=n.plus(m.times(i)),r.cmp(t)!=1;)n=i,i=r,r=u,u=c.plus(m.times(r)),c=r,r=e,e=a.minus(m.times(r)),a=r;return r=C(t.minus(n),i,0,1,1),c=c.plus(r.times(u)),n=n.plus(r.times(i)),c.s=u.s=b.s,d=C(u,i,o,1).minus(b).abs().cmp(C(c,n,o,1).minus(b).abs())<1?[u,i]:[c,n],P.precision=l,k=!0,d};p.toHexadecimal=p.toHex=function(t,e){return mt(this,16,t,e)};p.toNearest=function(t,e){var n=this,i=n.constructor;if(n=new i(n),t==null){if(!n.d)return n;t=new i(1),e=i.rounding}else{if(t=new i(t),e===void 0?e=i.rounding:U(e,0,8),!n.d)return t.s?n:t;if(!t.d)return t.s&&(t.s=n.s),t}return t.d[0]?(k=!1,n=C(n,t,0,e,1).times(t),k=!0,g(n)):(t.s=n.s,n=t),n};p.toNumber=function(){return+this};p.toOctal=function(t,e){return mt(this,8,t,e)};p.toPower=p.pow=function(t){var e,n,i,r,o,s,a=this,c=a.constructor,u=+(t=new c(t));if(!a.d||!t.d||!a.d[0]||!t.d[0])return new c(E(+a,u));if(a=new c(a),a.eq(1))return a;if(i=c.precision,o=c.rounding,t.eq(1))return g(a,i,o);if(e=V(t.e/A),e>=t.d.length-1&&(n=u<0?-u:u)<=Wn)return r=Ut(c,a,n,i),t.s<0?new c(1).div(r):g(r,i,o);if(s=a.s,s<0){if(e<t.d.length-1)return new c(NaN);if((t.d[e]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return n=E(+a,u),e=n==0||!isFinite(n)?V(u*(Math.log("0."+D(a.d))/Math.LN10+a.e+1)):new c(n+"").e,e>c.maxE+1||e<c.minE-1?new c(e>0?s/0:0):(k=!1,c.rounding=a.s=1,n=Math.min(12,(e+"").length),r=ct(t.times(ue(a,i+n)),i),r.d&&(r=g(r,i+5,1),Te(r.d,i,o)&&(e=i+10,r=g(ct(t.times(ue(a,e+n)),e),e+5,1),+D(r.d).slice(i+1,i+15)+1==1e14&&(r=g(r,i+1,0)))),r.s=s,k=!0,c.rounding=o,g(r,i,o))};p.toPrecision=function(t,e){var n,i=this,r=i.constructor;return t===void 0?n=te(i,i.e<=r.toExpNeg||i.e>=r.toExpPos):(U(t,1,le),e===void 0?e=r.rounding:U(e,0,8),i=g(new r(i),t,e),n=te(i,t<=i.e||i.e<=r.toExpNeg,t)),i.isNeg()&&!i.isZero()?"-"+n:n};p.toSignificantDigits=p.toSD=function(t,e){var n=this,i=n.constructor;return t===void 0?(t=i.precision,e=i.rounding):(U(t,1,le),e===void 0?e=i.rounding:U(e,0,8)),g(new i(n),t,e)};p.toString=function(){var t=this,e=t.constructor,n=te(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()&&!t.isZero()?"-"+n:n};p.truncated=p.trunc=function(){return g(new this.constructor(this),this.e+1,1)};p.valueOf=p.toJSON=function(){var t=this,e=t.constructor,n=te(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()?"-"+n:n};function D(t){var e,n,i,r=t.length-1,o="",s=t[0];if(r>0){for(o+=s,e=1;e<r;e++)i=t[e]+"",n=A-i.length,n&&(o+=ae(n)),o+=i;s=t[e],i=s+"",n=A-i.length,n&&(o+=ae(n))}else if(s===0)return"0";for(;s%10===0;)s/=10;return o+s}function U(t,e,n){if(t!==~~t||t<e||t>n)throw Error(ce+t)}function Te(t,e,n,i){var r,o,s,a;for(o=t[0];o>=10;o/=10)--e;return--e<0?(e+=A,r=0):(r=Math.ceil((e+1)/A),e%=A),o=E(10,A-e),a=t[r]%o|0,i==null?e<3?(e==0?a=a/100|0:e==1&&(a=a/10|0),s=n<4&&a==99999||n>3&&a==49999||a==5e4||a==0):s=(n<4&&a+1==o||n>3&&a+1==o/2)&&(t[r+1]/o/100|0)==E(10,e-2)-1||(a==o/2||a==0)&&(t[r+1]/o/100|0)==0:e<4?(e==0?a=a/1e3|0:e==1?a=a/100|0:e==2&&(a=a/10|0),s=(i||n<4)&&a==9999||!i&&n>3&&a==4999):s=((i||n<4)&&a+1==o||!i&&n>3&&a+1==o/2)&&(t[r+1]/o/1e3|0)==E(10,e-3)-1,s}function De(t,e,n){for(var i,r=[0],o,s=0,a=t.length;s<a;){for(o=r.length;o--;)r[o]*=e;for(r[0]+=st.indexOf(t.charAt(s++)),i=0;i<r.length;i++)r[i]>n-1&&(r[i+1]===void 0&&(r[i+1]=0),r[i+1]+=r[i]/n|0,r[i]%=n)}return r.reverse()}function Gn(t,e){var n,i,r;if(e.isZero())return e;i=e.d.length,i<32?(n=Math.ceil(i/3),r=(1/Ue(4,n)).toString()):(n=16,r="2.3283064365386962890625e-10"),t.precision+=n,e=ye(t,1,e.times(r),new t(1));for(var o=n;o--;){var s=e.times(e);e=s.times(s).minus(s).times(8).plus(1)}return t.precision-=n,e}var C=function(){function t(i,r,o){var s,a=0,c=i.length;for(i=i.slice();c--;)s=i[c]*r+a,i[c]=s%o|0,a=s/o|0;return a&&i.unshift(a),i}function e(i,r,o,s){var a,c;if(o!=s)c=o>s?1:-1;else for(a=c=0;a<o;a++)if(i[a]!=r[a]){c=i[a]>r[a]?1:-1;break}return c}function n(i,r,o,s){for(var a=0;o--;)i[o]-=a,a=i[o]<r[o]?1:0,i[o]=a*s+i[o]-r[o];for(;!i[0]&&i.length>1;)i.shift()}return function(i,r,o,s,a,c){var u,l,m,d,b,h,P,F,I,v,B,O,be,z,he,Oe,ke,rt,Y,Ee,ve=i.constructor,ot=i.s==r.s?1:-1,_=i.d,N=r.d;if(!_||!_[0]||!N||!N[0])return new ve(!i.s||!r.s||(_?N&&_[0]==N[0]:!N)?NaN:_&&_[0]==0||!N?ot*0:ot/0);for(c?(b=1,l=i.e-r.e):(c=$,b=A,l=V(i.e/b)-V(r.e/b)),Y=N.length,ke=_.length,I=new ve(ot),v=I.d=[],m=0;N[m]==(_[m]||0);m++);if(N[m]>(_[m]||0)&&l--,o==null?(z=o=ve.precision,s=ve.rounding):a?z=o+(i.e-r.e)+1:z=o,z<0)v.push(1),h=!0;else{if(z=z/b+2|0,m=0,Y==1){for(d=0,N=N[0],z++;(m<ke||d)&&z--;m++)he=d*c+(_[m]||0),v[m]=he/N|0,d=he%N|0;h=d||m<ke}else{for(d=c/(N[0]+1)|0,d>1&&(N=t(N,d,c),_=t(_,d,c),Y=N.length,ke=_.length),Oe=Y,B=_.slice(0,Y),O=B.length;O<Y;)B[O++]=0;Ee=N.slice(),Ee.unshift(0),rt=N[0],N[1]>=c/2&&++rt;do d=0,u=e(N,B,Y,O),u<0?(be=B[0],Y!=O&&(be=be*c+(B[1]||0)),d=be/rt|0,d>1?(d>=c&&(d=c-1),P=t(N,d,c),F=P.length,O=B.length,u=e(P,B,F,O),u==1&&(d--,n(P,Y<F?Ee:N,F,c))):(d==0&&(u=d=1),P=N.slice()),F=P.length,F<O&&P.unshift(0),n(B,P,O,c),u==-1&&(O=B.length,u=e(N,B,Y,O),u<1&&(d++,n(B,Y<O?Ee:N,O,c))),O=B.length):u===0&&(d++,B=[0]),v[m++]=d,u&&B[0]?B[O++]=_[Oe]||0:(B=[_[Oe]],O=1);while((Oe++<ke||B[0]!==void 0)&&z--);h=B[0]!==void 0}v[0]||v.shift()}if(b==1)I.e=l,Dt=h;else{for(m=1,d=v[0];d>=10;d/=10)m++;I.e=m+l*b-1,g(I,a?o+I.e+1:o,s,h)}return I}}();function g(t,e,n,i){var r,o,s,a,c,u,l,m,d,b=t.constructor;e:if(e!=null){if(m=t.d,!m)return t;for(r=1,a=m[0];a>=10;a/=10)r++;if(o=e-r,o<0)o+=A,s=e,l=m[d=0],c=l/E(10,r-s-1)%10|0;else if(d=Math.ceil((o+1)/A),a=m.length,d>=a)if(i){for(;a++<=d;)m.push(0);l=c=0,r=1,o%=A,s=o-A+1}else break e;else{for(l=a=m[d],r=1;a>=10;a/=10)r++;o%=A,s=o-A+r,c=s<0?0:l/E(10,r-s-1)%10|0}if(i=i||e<0||m[d+1]!==void 0||(s<0?l:l%E(10,r-s-1)),u=n<4?(c||i)&&(n==0||n==(t.s<0?3:2)):c>5||c==5&&(n==4||i||n==6&&(o>0?s>0?l/E(10,r-s):0:m[d-1])%10&1||n==(t.s<0?8:7)),e<1||!m[0])return m.length=0,u?(e-=t.e+1,m[0]=E(10,(A-e%A)%A),t.e=-e||0):m[0]=t.e=0,t;if(o==0?(m.length=d,a=1,d--):(m.length=d+1,a=E(10,A-o),m[d]=s>0?(l/E(10,r-s)%E(10,s)|0)*a:0),u)for(;;)if(d==0){for(o=1,s=m[0];s>=10;s/=10)o++;for(s=m[0]+=a,a=1;s>=10;s/=10)a++;o!=a&&(t.e++,m[0]==$&&(m[0]=1));break}else{if(m[d]+=a,m[d]!=$)break;m[d--]=0,a=1}for(o=m.length;m[--o]===0;)m.pop()}return k&&(t.e>b.maxE?(t.d=null,t.e=NaN):t.e<b.minE&&(t.e=0,t.d=[0])),t}function te(t,e,n){if(!t.isFinite())return Ht(t);var i,r=t.e,o=D(t.d),s=o.length;return e?(n&&(i=n-s)>0?o=o.charAt(0)+"."+o.slice(1)+ae(i):s>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(t.e<0?"e":"e+")+t.e):r<0?(o="0."+ae(-r-1)+o,n&&(i=n-s)>0&&(o+=ae(i))):r>=s?(o+=ae(r+1-s),n&&(i=n-r-1)>0&&(o=o+"."+ae(i))):((i=r+1)<s&&(o=o.slice(0,i)+"."+o.slice(i)),n&&(i=n-s)>0&&(r+1===s&&(o+="."),o+=ae(i))),o}function Ge(t,e){var n=t[0];for(e*=A;n>=10;n/=10)e++;return e}function We(t,e,n){if(e>qn)throw k=!0,n&&(t.precision=n),Error(_t);return g(new t(_e),e,1,!0)}function J(t,e,n){if(e>ut)throw Error(_t);return g(new t(Ve),e,n,!0)}function Gt(t){var e=t.length-1,n=e*A+1;if(e=t[e],e){for(;e%10==0;e/=10)n--;for(e=t[0];e>=10;e/=10)n++}return n}function ae(t){for(var e="";t--;)e+="0";return e}function Ut(t,e,n,i){var r,o=new t(1),s=Math.ceil(i/A+4);for(k=!1;;){if(n%2&&(o=o.times(e),Et(o.d,s)&&(r=!0)),n=V(n/2),n===0){n=o.d.length-1,r&&o.d[n]===0&&++o.d[n];break}e=e.times(e),Et(e.d,s)}return k=!0,o}function Ot(t){return t.d[t.d.length-1]&1}function Xt(t,e,n){for(var i,r=new t(e[0]),o=0;++o<e.length;)if(i=new t(e[o]),i.s)r[n](i)&&(r=i);else{r=i;break}return r}function ct(t,e){var n,i,r,o,s,a,c,u=0,l=0,m=0,d=t.constructor,b=d.rounding,h=d.precision;if(!t.d||!t.d[0]||t.e>17)return new d(t.d?t.d[0]?t.s<0?0:1/0:1:t.s?t.s<0?0:t:0/0);for(e==null?(k=!1,c=h):c=e,a=new d(.03125);t.e>-2;)t=t.times(a),m+=5;for(i=Math.log(E(2,m))/Math.LN10*2+5|0,c+=i,n=o=s=new d(1),d.precision=c;;){if(o=g(o.times(t),c,1),n=n.times(++l),a=s.plus(C(o,n,c,1)),D(a.d).slice(0,c)===D(s.d).slice(0,c)){for(r=m;r--;)s=g(s.times(s),c,1);if(e==null)if(u<3&&Te(s.d,c-i,b,u))d.precision=c+=10,n=o=a=new d(1),l=0,u++;else return g(s,d.precision=h,b,k=!0);else return d.precision=h,s}s=a}}function ue(t,e){var n,i,r,o,s,a,c,u,l,m,d,b=1,h=10,P=t,F=P.d,I=P.constructor,v=I.rounding,B=I.precision;if(P.s<0||!F||!F[0]||!P.e&&F[0]==1&&F.length==1)return new I(F&&!F[0]?-1/0:P.s!=1?NaN:F?0:P);if(e==null?(k=!1,l=B):l=e,I.precision=l+=h,n=D(F),i=n.charAt(0),Math.abs(o=P.e)<15e14){for(;i<7&&i!=1||i==1&&n.charAt(1)>3;)P=P.times(t),n=D(P.d),i=n.charAt(0),b++;o=P.e,i>1?(P=new I("0."+n),o++):P=new I(i+"."+n.slice(1))}else return u=We(I,l+2,B).times(o+""),P=ue(new I(i+"."+n.slice(1)),l-h).plus(u),I.precision=B,e==null?g(P,B,v,k=!0):P;for(m=P,c=s=P=C(P.minus(1),P.plus(1),l,1),d=g(P.times(P),l,1),r=3;;){if(s=g(s.times(d),l,1),u=c.plus(C(s,new I(r),l,1)),D(u.d).slice(0,l)===D(c.d).slice(0,l))if(c=c.times(2),o!==0&&(c=c.plus(We(I,l+2,B).times(o+""))),c=C(c,new I(b),l,1),e==null)if(Te(c.d,l-h,v,a))I.precision=l+=h,u=s=P=C(m.minus(1),m.plus(1),l,1),d=g(P.times(P),l,1),r=a=1;else return g(c,I.precision=B,v,k=!0);else return I.precision=B,c;c=u,r+=2}}function Ht(t){return String(t.s*t.s/0)}function lt(t,e){var n,i,r;for((n=e.indexOf("."))>-1&&(e=e.replace(".","")),(i=e.search(/e/i))>0?(n<0&&(n=i),n+=+e.slice(i+1),e=e.substring(0,i)):n<0&&(n=e.length),i=0;e.charCodeAt(i)===48;i++);for(r=e.length;e.charCodeAt(r-1)===48;--r);if(e=e.slice(i,r),e){if(r-=i,t.e=n=n-i-1,t.d=[],i=(n+1)%A,n<0&&(i+=A),i<r){for(i&&t.d.push(+e.slice(0,i)),r-=A;i<r;)t.d.push(+e.slice(i,i+=A));e=e.slice(i),i=A-e.length}else i-=r;for(;i--;)e+="0";t.d.push(+e),k&&(t.e>t.constructor.maxE?(t.d=null,t.e=NaN):t.e<t.constructor.minE&&(t.e=0,t.d=[0]))}else t.e=0,t.d=[0];return t}function Un(t,e){var n,i,r,o,s,a,c,u,l;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),qt.test(e))return lt(t,e)}else if(e==="Infinity"||e==="NaN")return+e||(t.s=NaN),t.e=NaN,t.d=null,t;if(_n.test(e))n=16,e=e.toLowerCase();else if(Dn.test(e))n=2;else if(Vn.test(e))n=8;else throw Error(ce+e);for(o=e.search(/p/i),o>0?(c=+e.slice(o+1),e=e.substring(2,o)):e=e.slice(2),o=e.indexOf("."),s=o>=0,i=t.constructor,s&&(e=e.replace(".",""),a=e.length,o=a-o,r=Ut(i,new i(n),o,o*2)),u=De(e,n,$),l=u.length-1,o=l;u[o]===0;--o)u.pop();return o<0?new i(t.s*0):(t.e=Ge(u,l),t.d=u,k=!1,s&&(t=C(t,r,a*4)),c&&(t=t.times(Math.abs(c)<54?E(2,c):Be.pow(2,c))),k=!0,t)}function Xn(t,e){var n,i=e.d.length;if(i<3)return e.isZero()?e:ye(t,2,e,e);n=1.4*Math.sqrt(i),n=n>16?16:n|0,e=e.times(1/Ue(5,n)),e=ye(t,2,e,e);for(var r,o=new t(5),s=new t(16),a=new t(20);n--;)r=e.times(e),e=e.times(o.plus(r.times(s.times(r).minus(a))));return e}function ye(t,e,n,i,r){var o,s,a,c,u=1,l=t.precision,m=Math.ceil(l/A);for(k=!1,c=n.times(n),a=new t(i);;){if(s=C(a.times(c),new t(e++*e++),l,1),a=r?i.plus(s):i.minus(s),i=C(s.times(c),new t(e++*e++),l,1),s=a.plus(i),s.d[m]!==void 0){for(o=m;s.d[o]===a.d[o]&&o--;);if(o==-1)break}o=a,a=i,i=s,s=o,u++}return k=!0,s.d.length=m+1,s}function Ue(t,e){for(var n=t;--e;)n*=t;return n}function Zt(t,e){var n,i=e.s<0,r=J(t,t.precision,1),o=r.times(.5);if(e=e.abs(),e.lte(o))return oe=i?4:1,e;if(n=e.divToInt(r),n.isZero())oe=i?3:2;else{if(e=e.minus(n.times(r)),e.lte(o))return oe=Ot(n)?i?2:3:i?4:1,e;oe=Ot(n)?i?1:4:i?3:2}return e.minus(r).abs()}function mt(t,e,n,i){var r,o,s,a,c,u,l,m,d,b=t.constructor,h=n!==void 0;if(h?(U(n,1,le),i===void 0?i=b.rounding:U(i,0,8)):(n=b.precision,i=b.rounding),!t.isFinite())l=Ht(t);else{for(l=te(t),s=l.indexOf("."),h?(r=2,e==16?n=n*4-3:e==8&&(n=n*3-2)):r=e,s>=0&&(l=l.replace(".",""),d=new b(1),d.e=l.length-s,d.d=De(te(d),10,r),d.e=d.d.length),m=De(l,10,r),o=c=m.length;m[--c]==0;)m.pop();if(!m[0])l=h?"0p+0":"0";else{if(s<0?o--:(t=new b(t),t.d=m,t.e=o,t=C(t,d,n,i,0,r),m=t.d,o=t.e,u=Dt),s=m[n],a=r/2,u=u||m[n+1]!==void 0,u=i<4?(s!==void 0||u)&&(i===0||i===(t.s<0?3:2)):s>a||s===a&&(i===4||u||i===6&&m[n-1]&1||i===(t.s<0?8:7)),m.length=n,u)for(;++m[--n]>r-1;)m[n]=0,n||(++o,m.unshift(1));for(c=m.length;!m[c-1];--c);for(s=0,l="";s<c;s++)l+=st.charAt(m[s]);if(h){if(c>1)if(e==16||e==8){for(s=e==16?4:3,--c;c%s;c++)l+="0";for(m=De(l,r,e),c=m.length;!m[c-1];--c);for(s=1,l="1.";s<c;s++)l+=st.charAt(m[s])}else l=l.charAt(0)+"."+l.slice(1);l=l+(o<0?"p":"p+")+o}else if(o<0){for(;++o;)l="0"+l;l="0."+l}else if(++o>c)for(o-=c;o--;)l+="0";else o<c&&(l=l.slice(0,o)+"."+l.slice(o))}l=(e==16?"0x":e==2?"0b":e==8?"0o":"")+l}return t.s<0?"-"+l:l}function Et(t,e){if(t.length>e)return t.length=e,!0}function Hn(t){return new this(t).abs()}function Zn(t){return new this(t).acos()}function zn(t){return new this(t).acosh()}function jn(t,e){return new this(t).plus(e)}function Qn(t){return new this(t).asin()}function Yn(t){return new this(t).asinh()}function Jn(t){return new this(t).atan()}function $n(t){return new this(t).atanh()}function ei(t,e){t=new this(t),e=new this(e);var n,i=this.precision,r=this.rounding,o=i+4;return!t.s||!e.s?n=new this(NaN):!t.d&&!e.d?(n=J(this,o,1).times(e.s>0?.25:.75),n.s=t.s):!e.d||t.isZero()?(n=e.s<0?J(this,i,r):new this(0),n.s=t.s):!t.d||e.isZero()?(n=J(this,o,1).times(.5),n.s=t.s):e.s<0?(this.precision=o,this.rounding=1,n=this.atan(C(t,e,o,1)),e=J(this,o,1),this.precision=i,this.rounding=r,n=t.s<0?n.minus(e):n.plus(e)):n=this.atan(C(t,e,o,1)),n}function ti(t){return new this(t).cbrt()}function ni(t){return g(t=new this(t),t.e+1,2)}function ii(t,e,n){return new this(t).clamp(e,n)}function ri(t){if(!t||typeof t!="object")throw Error(qe+"Object expected");var e,n,i,r=t.defaults===!0,o=["precision",1,le,"rounding",0,8,"toExpNeg",-ge,0,"toExpPos",0,ge,"maxE",0,ge,"minE",-ge,0,"modulo",0,9];for(e=0;e<o.length;e+=3)if(n=o[e],r&&(this[n]=at[n]),(i=t[n])!==void 0)if(V(i)===i&&i>=o[e+1]&&i<=o[e+2])this[n]=i;else throw Error(ce+n+": "+i);if(n="crypto",r&&(this[n]=at[n]),(i=t[n])!==void 0)if(i===!0||i===!1||i===0||i===1)if(i)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(Vt);else this[n]=!1;else throw Error(ce+n+": "+i);return this}function oi(t){return new this(t).cos()}function si(t){return new this(t).cosh()}function zt(t){var e,n,i;function r(o){var s,a,c,u=this;if(!(u instanceof r))return new r(o);if(u.constructor=r,vt(o)){u.s=o.s,k?!o.d||o.e>r.maxE?(u.e=NaN,u.d=null):o.e<r.minE?(u.e=0,u.d=[0]):(u.e=o.e,u.d=o.d.slice()):(u.e=o.e,u.d=o.d?o.d.slice():o.d);return}if(c=typeof o,c==="number"){if(o===0){u.s=1/o<0?-1:1,u.e=0,u.d=[0];return}if(o<0?(o=-o,u.s=-1):u.s=1,o===~~o&&o<1e7){for(s=0,a=o;a>=10;a/=10)s++;k?s>r.maxE?(u.e=NaN,u.d=null):s<r.minE?(u.e=0,u.d=[0]):(u.e=s,u.d=[o]):(u.e=s,u.d=[o]);return}else if(o*0!==0){o||(u.s=NaN),u.e=NaN,u.d=null;return}return lt(u,o.toString())}else if(c!=="string")throw Error(ce+o);return(a=o.charCodeAt(0))===45?(o=o.slice(1),u.s=-1):(a===43&&(o=o.slice(1)),u.s=1),qt.test(o)?lt(u,o):Un(u,o)}if(r.prototype=p,r.ROUND_UP=0,r.ROUND_DOWN=1,r.ROUND_CEIL=2,r.ROUND_FLOOR=3,r.ROUND_HALF_UP=4,r.ROUND_HALF_DOWN=5,r.ROUND_HALF_EVEN=6,r.ROUND_HALF_CEIL=7,r.ROUND_HALF_FLOOR=8,r.EUCLID=9,r.config=r.set=ri,r.clone=zt,r.isDecimal=vt,r.abs=Hn,r.acos=Zn,r.acosh=zn,r.add=jn,r.asin=Qn,r.asinh=Yn,r.atan=Jn,r.atanh=$n,r.atan2=ei,r.cbrt=ti,r.ceil=ni,r.clamp=ii,r.cos=oi,r.cosh=si,r.div=ai,r.exp=ui,r.floor=ci,r.hypot=li,r.ln=mi,r.log=di,r.log10=fi,r.log2=pi,r.max=bi,r.min=gi,r.mod=yi,r.mul=wi,r.pow=Pi,r.random=Ai,r.round=hi,r.sign=ki,r.sin=Ti,r.sinh=Bi,r.sqrt=xi,r.sub=Ii,r.sum=Si,r.tan=Ci,r.tanh=Ni,r.trunc=Ki,t===void 0&&(t={}),t&&t.defaults!==!0)for(i=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],e=0;e<i.length;)t.hasOwnProperty(n=i[e++])||(t[n]=this[n]);return r.config(t),r}function ai(t,e){return new this(t).div(e)}function ui(t){return new this(t).exp()}function ci(t){return g(t=new this(t),t.e+1,3)}function li(){var t,e,n=new this(0);for(k=!1,t=0;t<arguments.length;)if(e=new this(arguments[t++]),e.d)n.d&&(n=n.plus(e.times(e)));else{if(e.s)return k=!0,new this(1/0);n=e}return k=!0,n.sqrt()}function vt(t){return t instanceof Be||t&&t.toStringTag===Wt||!1}function mi(t){return new this(t).ln()}function di(t,e){return new this(t).log(e)}function pi(t){return new this(t).log(2)}function fi(t){return new this(t).log(10)}function bi(){return Xt(this,arguments,"lt")}function gi(){return Xt(this,arguments,"gt")}function yi(t,e){return new this(t).mod(e)}function wi(t,e){return new this(t).mul(e)}function Pi(t,e){return new this(t).pow(e)}function Ai(t){var e,n,i,r,o=0,s=new this(1),a=[];if(t===void 0?t=this.precision:U(t,1,le),i=Math.ceil(t/A),this.crypto)if(crypto.getRandomValues)for(e=crypto.getRandomValues(new Uint32Array(i));o<i;)r=e[o],r>=429e7?e[o]=crypto.getRandomValues(new Uint32Array(1))[0]:a[o++]=r%1e7;else if(crypto.randomBytes){for(e=crypto.randomBytes(i*=4);o<i;)r=e[o]+(e[o+1]<<8)+(e[o+2]<<16)+((e[o+3]&127)<<24),r>=214e7?crypto.randomBytes(4).copy(e,o):(a.push(r%1e7),o+=4);o=i/4}else throw Error(Vt);else for(;o<i;)a[o++]=Math.random()*1e7|0;for(i=a[--o],t%=A,i&&t&&(r=E(10,A-t),a[o]=(i/r|0)*r);a[o]===0;o--)a.pop();if(o<0)n=0,a=[0];else{for(n=-1;a[0]===0;n-=A)a.shift();for(i=1,r=a[0];r>=10;r/=10)i++;i<A&&(n-=A-i)}return s.e=n,s.d=a,s}function hi(t){return g(t=new this(t),t.e+1,this.rounding)}function ki(t){return t=new this(t),t.d?t.d[0]?t.s:0*t.s:t.s||NaN}function Ti(t){return new this(t).sin()}function Bi(t){return new this(t).sinh()}function xi(t){return new this(t).sqrt()}function Ii(t,e){return new this(t).sub(e)}function Si(){var t=0,e=arguments,n=new this(e[t]);for(k=!1;n.s&&++t<e.length;)n=n.plus(e[t]);return k=!0,g(n,this.precision,this.rounding)}function Ci(t){return new this(t).tan()}function Ni(t){return new this(t).tanh()}function Ki(t){return g(t=new this(t),t.e+1,1)}p[Symbol.for("nodejs.util.inspect.custom")]=p.toString;p[Symbol.toStringTag]="Decimal";var Be=p.constructor=zt(at);_e=new Be(_e);Ve=new Be(Ve);var x=Be;import{PublicKey as zr}from"@solana/web3.js";import{get as jt,set as Li}from"lodash";var dt=class{constructor(e){this.logLevel=e.logLevel!==void 0?e.logLevel:0,this.name=e.name}set level(e){this.logLevel=e}get time(){return Date.now().toString()}get moduleName(){return this.name}isLogLevel(e){return e<=this.logLevel}error(...e){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...e),this):this}logWithError(...e){let n=e.map(i=>typeof i=="object"?JSON.stringify(i):i).join(", ");throw new Error(n)}warning(...e){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...e),this):this}info(...e){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...e),this):this}debug(...e){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...e),this):this}},Qt={},Ri={};function q(t){let e=jt(Qt,t);if(!e){let n=jt(Ri,t);e=new dt({name:t,logLevel:n}),Li(Qt,t,e)}return e}import{MINT_SIZE as Jr,TOKEN_PROGRAM_ID as $r,getTransferFeeConfig as eo,unpackMint as to}from"@solana/spl-token";var no=q("Raydium_accountInfo_util");import ie from"bn.js";import Vi from"big.js";import ho from"bn.js";import Mi from"toformat";var Fi=Mi,xe=Fi;import Ze from"big.js";import Ei from"bn.js";import vi from"decimal.js-light";import Ie from"bn.js";var Jt=9007199254740991;function ne(t){let e=q("Raydium_parseBigNumberish");if(t instanceof Ie)return t;if(typeof t=="string"){if(t.match(/^-?[0-9]+$/))return new Ie(t);e.logWithError(`invalid BigNumberish string: ${t}`)}return typeof t=="number"?(t%1&&e.logWithError(`BigNumberish number underflow: ${t}`),(t>=Jt||t<=-Jt)&&e.logWithError(`BigNumberish number overflow: ${t}`),new Ie(String(t))):typeof t=="bigint"?new Ie(t.toString()):(e.error(`invalid BigNumberish value: ${t}`),new Ie(0))}var He=q("module/fraction"),pt=xe(Ze),Se=xe(vi),Di={[0]:Se.ROUND_DOWN,[1]:Se.ROUND_HALF_UP,[2]:Se.ROUND_UP},_i={[0]:Ze.roundDown,[1]:Ze.roundHalfUp,[2]:Ze.roundUp},K=class{constructor(e,n=new Ei(1)){this.numerator=ne(e),this.denominator=ne(n)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new K(this.denominator,this.numerator)}add(e){let n=e instanceof K?e:new K(ne(e));return this.denominator.eq(n.denominator)?new K(this.numerator.add(n.numerator),this.denominator):new K(this.numerator.mul(n.denominator).add(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}sub(e){let n=e instanceof K?e:new K(ne(e));return this.denominator.eq(n.denominator)?new K(this.numerator.sub(n.numerator),this.denominator):new K(this.numerator.mul(n.denominator).sub(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}mul(e){let n=e instanceof K?e:new K(ne(e));return new K(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(e){let n=e instanceof K?e:new K(ne(e));return new K(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(e,n={groupSeparator:""},i=1){Number.isInteger(e)||He.logWithError(`${e} is not an integer.`),e<=0&&He.logWithError(`${e} is not positive.`),Se.set({precision:e+1,rounding:Di[i]});let r=new Se(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return r.toFormat(r.decimalPlaces(),n)}toFixed(e,n={groupSeparator:""},i=1){return Number.isInteger(e)||He.logWithError(`${e} is not an integer.`),e<0&&He.logWithError(`${e} is negative.`),pt.DP=e,pt.RM=_i[i]||1,new pt(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,n)}isZero(){return this.numerator.isZero()}};var Ko=q("Raydium_amount"),Lo=xe(Vi);import{PublicKey as qi}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as $t}from"@solana/spl-token";var ft={chainId:101,address:qi.default.toBase58(),programId:$t.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},me={chainId:101,address:"So11111111111111111111111111111111111111112",programId:$t.toBase58(),decimals:9,symbol:"WSOL",name:"Wrapped SOL",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}};import{PublicKey as gt}from"@solana/web3.js";import{PublicKey as L,SystemProgram as en,SYSVAR_RENT_PUBKEY as Gi}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Ui}from"@solana/spl-token";function bt({pubkey:t,isSigner:e=!1,isWritable:n=!0}){return{pubkey:t,isWritable:n,isSigner:e}}var _o=[bt({pubkey:Ui,isWritable:!1}),bt({pubkey:en.programId,isWritable:!1}),bt({pubkey:Gi,isWritable:!1})];function tn({publicKey:t,transformSol:e}){let n=nn(t.toString());if(n instanceof L)return e&&n.equals(Ce)?Xe:n;if(e&&n.toString()===Ce.toBase58())return Xe;if(typeof n=="string"){if(n===L.default.toBase58())return L.default;try{return new L(n)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function nn(t){try{return new L(t)}catch{return t}}var Xi=new L("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Hi=new L("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Zi=new L("SysvarRent111111111111111111111111111111111"),Vo=new L("SysvarC1ock11111111111111111111111111111111"),rn=new L("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Wo=new L("Sysvar1nstructions1111111111111111111111111"),qo=en.programId,Go=new L("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Uo=new L("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Xo=new L("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Ho=new L("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Zo=new L("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),zo=new L("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),jo=new L("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Qo=new L("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Yo=new L("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Jo=new L("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),$o=new L("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),Xe=new L("So11111111111111111111111111111111111111112"),Ce=L.default;var yt=class{constructor({mint:e,decimals:n,symbol:i,name:r,skipMint:o=!1,isToken2022:s=!1}){if(e===Ce.toBase58()||e instanceof gt&&Ce.equals(e)){this.decimals=me.decimals,this.symbol=me.symbol,this.name=me.name,this.mint=new gt(me.address),this.isToken2022=!1;return}this.decimals=n,this.symbol=i||e.toString().substring(0,6),this.name=r||e.toString().substring(0,6),this.mint=o?gt.default:tn({publicKey:e}),this.isToken2022=s}equals(e){return this===e?!0:this.mint.equals(e.mint)}},de=yt;de.WSOL=new yt(j(H({},me),{mint:me.address}));var wt=class{constructor({decimals:e,symbol:n="UNKNOWN",name:i="UNKNOWN"}){this.decimals=e,this.symbol=n,this.name=i}equals(e){return this===e}},ze=wt;ze.SOL=new wt(ft);import zi from"bn.js";var ms=new K(new zi(100));var ys=q("Raydium_price");import{PublicKey as Fs}from"@solana/web3.js";import Es from"bn.js";var ji=new ie(0),ea=new ie(1),ta=new ie(2),na=new ie(3),ia=new ie(5),Wi=new ie(10),ra=new ie(100),oa=new ie(1e3),sa=new ie(1e4);function on(t,e,n){return t.mul(e).add(n).sub(new ie(1)).div(n)}import{PublicKey as La}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Ma}from"@solana/spl-token";import{ComputeBudgetProgram as fa,Keypair as ya,PublicKey as wa,Transaction as Aa,TransactionMessage as ka,VersionedTransaction as Ta}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Sa}from"@solana/spl-token";var Ca=q("Raydium_txUtil");import{PublicKey as f}from"@solana/web3.js";var va=new f("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),Da=new f("CBuCnLe26faBpcBP2fktp4rp8abpcAnTWft6ZrP5Q4T"),_a=new f("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),Va=new f("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),Wa=new f("Ray1111111111111111111111111111111111111111"),qa=new f("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),Ga=new f("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),Ua=new f("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),Xa=new f("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),Ha=new f("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),Za=new f("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),Yi=new f("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),Ji=new f("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),$i=new f("kN1kEznaF5Xbd8LYuqtEFcxzWSBk5Fv6ygX6SqEGJVy"),za=new f("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),sn=new f("Ray1111111111111111111111111111111111111111"),ja=new f("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),Qa=new f("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),Ya=new f("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),Ja=new f("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),$a=new f("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),eu=new f("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),tu=new f("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),nu=new f("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),iu=new f("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),er=new f("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),tr=new f("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),nr=new f("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2"),ru=new f("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),ir=new f("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),ou=new f("3f7GcQFG397GAaEnv51zR6tsTVihYRydnydDD1cXekxH"),rr=new f("7AFUeLVRjBfzqK3tTGw8hN48KLQWSk6DTE8xprWdPqix"),su=new f("LanMV9sAd7wArD4vJFi2qDdfnVhFxYSUg6eADduJ3uj"),au=new f("WLHv2UAZm6z4KyaaELi5pjdbJh6RESMva1Rnn8pJVVh"),or=new f("LanD8FpTBBvzZFXjTxsAoipkFsxPUCDB4qAqKxYDiNP"),sr=new f("HYNHiyKJ3gGVFvyxJAurK7qr7P2o5J9THmvCGMdULtpW"),uu=new f("4Bu96XjU84XjPDSpveTVf6LYGCkfW5FK7SNkREWcEfV4"),an=new f("2Jx4KTDrVSdWNazuGpcA8n3ZLTRGGBDxAWhuKe2Xcj2a"),cu=new f("6s1xP3hpbAfFoNtUNF8mfHsjr2Bd97JxFJRWLbL6aHuX"),un=new f("7ZR4zD7PYfY2XxoG1Gxcy2EgEeGYrpxrwzPuwdUBssEt");var lu={AMM_V4:new f("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),AMM_STABLE:new f("DDg4VmQaJV9ogWce7LpcjBA9bv22wRp5uaTPa5pGjijF"),CLMM_PROGRAM_ID:new f("devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH"),CLMM_LOCK_PROGRAM_ID:new f("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),CLMM_LOCK_AUTH_ID:new f("8qmHNvu2Kr2C7U8mJL4Vz1vTDxMhVuXKREwU7TNoaVEo"),FARM_PROGRAM_ID_V3:new f("85BFyr98MbCUU9MVTEgzx1nbhWACbJqLzho6zd6DZcWL"),FARM_PROGRAM_ID_V5:new f("EcLzTrNg9V7qhcdyXDe2qjtPkiGzDM2UbdRaeaadU5r2"),FARM_PROGRAM_ID_V6:new f("Farm2hJLcqPtPg8M4rR6DMrsRNc5TPm5Cs4bVQrMe2T7"),OPEN_BOOK_PROGRAM:new f("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),SERUM_PROGRAM_ID_V3:f.default,UTIL1216:f.default,Router:new f("BVChZ3XFEwTMUk1o9i3HAf91H6mFxSwa5X2wFAWhYPhU"),CREATE_CPMM_POOL_PROGRAM:er,CREATE_CPMM_POOL_AUTH:tr,CREATE_CPMM_POOL_FEE_ACC:nr,LOCK_CPMM_PROGRAM:ir,LOCK_CPMM_AUTH:rr,LAUNCHPAD_PROGRAM:or,LAUNCHPAD_AUTH:sr,LAUNCHPAD_PLATFORM:an,LAUNCHPAD_CONFIG:un,FEE_DESTINATION_ID:new f("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR"),MODEL_DATA_PUBKEY:sn},mu={OPEN_BOOK_PROGRAM:new f("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),SERUM_PROGRAM_ID_V3:new f("Ray1111111111111111111111111111111111111111"),AMM_V4:new f("DRaya7Kj3aMWQSy19kSjvmuwq9docCHofyP9kanQGaav"),AMM_STABLE:new f("DRayDdXc1NZQ9C3hRWmoSf8zK4iapgMnjdNZWrfwsP8m"),CLMM_PROGRAM_ID:new f("DRayAUgENGQBKVaX8owNhgzkEDyoHTGVEGHVJT1E9pfH"),CLMM_LOCK_PROGRAM_ID:new f("DRay25Usp3YJAi7beckgpGUC7mGJ2cR1AVPxhYfwVCUX"),CLMM_LOCK_AUTH_ID:new f("6Aoh8h2Lw2m5UGxYR8AdAL87jTWYeKoxM52mJRzfYwN"),CREATE_CPMM_POOL_PROGRAM:new f("DRaycpLY18LhpbydsBWbVJtxpNv9oXPgjRSfpF2bWpYb"),CREATE_CPMM_POOL_AUTH:new f("CXniRufdq5xL8t8jZAPxsPZDpuudwuJSPWnbcD5Y5Nxq"),CREATE_CPMM_POOL_FEE_ACC:new f("3oE58BKVt8KuYkGxx8zBojugnymWmBiyafWgMrnb6eYy"),LOCK_CPMM_PROGRAM:new f("DRay25Usp3YJAi7beckgpGUC7mGJ2cR1AVPxhYfwVCUX"),LOCK_CPMM_AUTH:new f("7qWVV8UY2bRJfDLP4s37YzBPKUkVB46DStYJBpYbQzu3"),UTIL1216:f.default,Router:new f("DRaybByLpbUL57LJARs3j8BitTxVfzBg351EaMr5UTCd"),FARM_PROGRAM_ID_V3:new f("DRayWyrLmEW5KEeqs8kdTMMaBabapqagaBC7KWpGtJeZ"),FARM_PROGRAM_ID_V5:new f("DRayiCGSZgku1GTK6rXD6mVDdingXy6APAH1R6R5L2LC"),FARM_PROGRAM_ID_V6:new f("DRayzbYakXs45ELHkzH6vC3fuhQqTAnv5A68gdFuvZyZ"),LAUNCHPAD_PROGRAM:new f("DRay6fNdQ5J82H7xV6uq2aV3mNrUZ1J4PgSKsWgptcm6"),LAUNCHPAD_AUTH:new f("5xqNaZXX5eUi4p5HU4oz9i5QnwRNT2y6oN7yyn4qENeq"),LAUNCHPAD_PLATFORM:an,LAUNCHPAD_CONFIG:un,FEE_DESTINATION_ID:new f("9y8ENuuZ3b19quffx9hQvRVygG5ky6snHfRvGpuSfeJy"),MODEL_DATA_PUBKEY:sn};import Qe from"bn.js";function Ye(t,e){if(t.isZero())return new Qe(0);let n=t.div(e);return n.isZero()?new Qe(1):t.mod(e).gt(new Qe(0))?n.add(new Qe(1)):n}import{PublicKey as ar,AddressLookupTableAccount as cn}from"@solana/web3.js";var ur={AcL1Vo8oy1ULiavEcjSUcwfBSForXMudcZvDZy5nzJkU:new cn({key:new ar("AcL1Vo8oy1ULiavEcjSUcwfBSForXMudcZvDZy5nzJkU"),state:cn.deserialize(Buffer.from("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","base64"))})};import{PublicKey as Ku,sendAndConfirmTransaction as Lu,SystemProgram as Fu,Transaction as Ou,TransactionMessage as vu,VersionedTransaction as Du}from"@solana/web3.js";import Vu from"axios";import mr from"bn.js";var fe=new mr(1e6);var pe=class{static getPoolInitPriceByPool({poolInfo:e,decimalA:n,decimalB:i}){throw Error()}static getPoolInitPriceByInit({a:e,b:n,decimalA:i,decimalB:r}){throw Error()}static getPoolPrice({poolInfo:e,decimalA:n,decimalB:i}){throw Error()}static getPoolEndPrice({supply:e,totalSell:n,totalLockedAmount:i,totalFundRaising:r,migrateFee:o,decimalA:s,decimalB:a}){throw Error()}static getPoolEndPriceReal({poolInfo:e,decimalA:n,decimalB:i}){throw Error()}static getInitParam({supply:e,totalFundRaising:n,totalSell:i,totalLockedAmount:r,migrateFee:o}){throw Error()}static buyExactIn({poolInfo:e,amount:n}){throw Error()}static buyExactOut({poolInfo:e,amount:n}){throw Error()}static sellExactIn({poolInfo:e,amount:n}){throw Error()}static sellExactOut({poolInfo:e,amount:n}){throw Error()}};import{PublicKey as mp}from"@solana/web3.js";import pp from"bn.js";import{AccountLayout as yp,createAssociatedTokenAccountIdempotentInstruction as wp,TOKEN_2022_PROGRAM_ID as Pp,TOKEN_PROGRAM_ID as Ap}from"@solana/spl-token";import{PublicKey as gc}from"@solana/web3.js";import{MintLayout as wc,TOKEN_PROGRAM_ID as Ac}from"@solana/spl-token";import{Keypair as Fd,PublicKey as Od,SystemProgram as vd,TransactionInstruction as Dd}from"@solana/web3.js";import Vd from"bn.js";import{ASSOCIATED_TOKEN_PROGRAM_ID as Gd,TOKEN_2022_PROGRAM_ID as Ud,TOKEN_PROGRAM_ID as Xd}from"@solana/spl-token";import{PublicKey as Ar}from"@solana/web3.js";import fn,{isBN as bn}from"bn.js";import{bits as Rc,BitStructure as Mc,blob as dr,Blob as Fc,cstr as Oc,f32 as Ec,f32be as vc,f64 as Dc,f64be as _c,greedy as Vc,Layout as pr,ns64 as Wc,ns64be as qc,nu64 as Gc,nu64be as Uc,offset as Xc,s16 as Hc,s16be as Zc,s24 as zc,s24be as jc,s32 as fr,s32be as Qc,s40 as Yc,s40be as Jc,s48 as $c,s48be as el,s8 as tl,seq as br,struct as nl,Structure as gr,u16 as yr,u16be as il,u24 as rl,u24be as ol,u32 as sl,u32be as al,u40 as ul,u40be as cl,u48 as ll,u48be as ml,u8 as wr,UInt as Pr,union as dl,Union as pl,unionLayoutDiscriminator as fl,utf8 as bl}from"@solana/buffer-layout";var kt=pr,mn=gr;var Tt=Pr;var dn=wr,Ne=yr;var se=fr;var pn=br;var Z=dr;var we=class extends kt{constructor(n,i,r){super(n,r);this.blob=Z(n),this.signed=i}decode(n,i=0){let r=new fn(this.blob.decode(n,i),10,"le");return this.signed?r.fromTwos(this.span*8).clone():r}encode(n,i,r=0){return typeof n=="number"&&(n=new fn(n)),this.signed&&(n=n.toTwos(this.span*8)),this.blob.encode(n.toArrayLike(Buffer,"le",this.span),i,r)}};function G(t){return new Tt(1,t)}function Pe(t){return new Tt(4,t)}function T(t){return new we(8,!1,t)}function R(t){return new we(16,!1,t)}function gn(t){return new we(8,!0,t)}function yn(t){return new we(16,!0,t)}var Je=class extends kt{constructor(n,i,r,o){super(n.span,o);this.layout=n,this.decoder=i,this.encoder=r}decode(n,i){return this.decoder(this.layout.decode(n,i))}encode(n,i,r){return this.layout.encode(this.encoder(n),i,r)}getSpan(n,i){return this.layout.getSpan(n,i)}};function S(t){return new Je(Z(32),e=>new Ar(e),e=>e.toBuffer(),t)}function xt(t){return new Je(dn(),hr,kr,t)}function hr(t){if(t===0)return!1;if(t===1)return!0;throw new Error("Invalid bool: "+t)}function kr(t){return t?1:0}var Bt=class extends mn{decode(e,n){return super.decode(e,n)}};function W(t,e,n){return new Bt(t,e,n)}function M(t,e,n){let i,r=typeof e=="number"?e:bn(e)?e.toNumber():new Proxy(e,{get(o,s){if(!i){let a=Reflect.get(o,"count");i=bn(a)?a.toNumber():a,Reflect.set(o,"count",i)}return Reflect.get(o,s)},set(o,s,a){return s==="count"&&(i=a),Reflect.set(o,s,a)}});return pn(t,r,n)}import pd from"bn.js";import Q from"bn.js";var It=new Q(0),wn=new Q(1),Pn=new Q(-1),ee=new Q(1).shln(64),An=new Q(1).shln(128),St=ee.sub(wn);var Tr=An.subn(1),Ae=-443636,Ke=-Ae,Ct=new Q("4295048016"),Nt=new Q("79226673521066979257578248091"),Nl=new Q("4295048017"),Kl=new Q("79226673521066979257578248090");var Br=new Q(10).pow(new Q(6));var Ll=new Q("18446744073700000000");import $m from"bn.js";var Dl=Buffer.from("amm_config","utf8"),_l=Buffer.from("pool","utf8"),Vl=Buffer.from("pool_vault","utf8"),Wl=Buffer.from("pool_reward_vault","utf8"),ql=Buffer.from("position","utf8"),Gl=Buffer.from("tick_array","utf8"),Ul=Buffer.from("operation","utf8"),Xl=Buffer.from("pool_tick_array_bitmap_extension","utf8"),Hl=Buffer.from("observation","utf8");var Zl=Buffer.from("locked_position","utf8");var zl=Buffer.from("support_mint","utf8");import{PublicKey as Sm}from"@solana/web3.js";import{TOKEN_2022_PROGRAM_ID as Nm}from"@solana/spl-token";import Lm from"bn.js";import Yl from"bn.js";var Rt=14;var $e=60;var Nr=W([Z(8),G("bump"),Ne("index"),S(""),Pe("protocolFeeRate"),Pe("tradeFeeRate"),Ne("tickSpacing"),M(T(),8,"")]),Kr=W([Pe("blockTimestamp"),gn("tickCumulative"),M(T(),4)]),Kn=W([Z(8),xt("initialized"),T("recentEpoch"),Ne("observationIndex"),S("poolId"),M(Kr,100,"observations"),M(T(),4)]),Lr=W([G("rewardState"),T("openTime"),T("endTime"),T("lastUpdateTime"),R("emissionsPerSecondX64"),T("rewardTotalEmissioned"),T("rewardClaimed"),S("tokenMint"),S("tokenVault"),S("creator"),R("rewardGrowthGlobalX64")]),Sn=W([Z(8),G("bump"),S("ammConfig"),S("creator"),S("mintA"),S("mintB"),S("vaultA"),S("vaultB"),S("observationId"),G("mintDecimalsA"),G("mintDecimalsB"),Ne("tickSpacing"),R("liquidity"),R("sqrtPriceX64"),se("tickCurrent"),Pe(),R("feeGrowthGlobalX64A"),R("feeGrowthGlobalX64B"),T("protocolFeesTokenA"),T("protocolFeesTokenB"),R("swapInAmountTokenA"),R("swapOutAmountTokenB"),R("swapInAmountTokenB"),R("swapOutAmountTokenA"),G("status"),M(G(),7,""),M(Lr,3,"rewardInfos"),M(T(),16,"tickArrayBitmap"),T("totalFeesTokenA"),T("totalFeesClaimedTokenA"),T("totalFeesTokenB"),T("totalFeesClaimedTokenB"),T("fundFeesTokenA"),T("fundFeesTokenB"),T("startTime"),M(T(),15*4-3,"padding")]),Rr=W([R("growthInsideLastX64"),T("rewardAmountOwed")]),Cn=W([Z(8),G("bump"),S("nftMint"),S("poolId"),se("tickLower"),se("tickUpper"),R("liquidity"),R("feeGrowthInsideLastX64A"),R("feeGrowthInsideLastX64B"),T("tokenFeesOwedA"),T("tokenFeesOwedB"),M(Rr,3,"rewardInfos"),M(T(),8,"")]),Td=W([Z(8),G("bump"),S("poolId"),se("tickLowerIndex"),se("tickUpperIndex"),R("liquidity"),R("feeGrowthInsideLastX64A"),R("feeGrowthInsideLastX64B"),T("tokenFeesOwedA"),T("tokenFeesOwedB"),M(R(),3,"rewardGrowthInside"),M(T(),8,"")]),Mr=W([se("tick"),yn("liquidityNet"),R("liquidityGross"),R("feeGrowthOutsideX64A"),R("feeGrowthOutsideX64B"),M(R(),3,"rewardGrowthsOutsideX64"),M(Pe(),13,"")]),Bn=W([Z(8),S("poolId"),se("startTickIndex"),M(Mr,$e,"ticks"),G("initializedTickCount"),M(G(),115,"")]),Fr=W([Z(329),M(S(),100,"whitelistMints")]),Cr=W([Z(8),S("poolId"),M(M(T(),8),Rt,"positiveTickArrayBitmap"),M(M(T(),8),Rt,"negativeTickArrayBitmap")]),Bd=W([T(),G("bump"),S("owner"),S("poolId"),S("positionId"),S("nftAccount"),M(T(),8)]),Or=W([Z(8),G("bump"),S("lockOwner"),S("poolId"),S("positionId"),S("nftAccount"),S("lockNftMint"),T("recentEpoch"),M(T(),8)]);Kn.span;var ep=q("Raydium_Clmm");var et=class extends pe{static getPoolInitPriceByPool({poolInfo:e,decimalA:n,decimalB:i}){return new x(e.virtualB.toString()).div(e.virtualA.toString()).mul(10**(n-i))}static getPoolInitPriceByInit({a:e,b:n,decimalA:i,decimalB:r}){return new x(n.toString()).div(e.toString()).mul(10**(i-r))}static getPoolPrice({poolInfo:e,decimalA:n,decimalB:i}){return new x(e.virtualB.add(e.realB).toString()).div(e.virtualA.sub(e.realA).toString()).mul(10**(n-i))}static getPoolEndPrice({supply:e,totalSell:n,totalLockedAmount:i,totalFundRaising:r,migrateFee:o,decimalA:s,decimalB:a}){return new x(r.sub(o).toString()).div(e.sub(n).sub(i).toString()).mul(10**(s-a))}static getPoolEndPriceReal({poolInfo:e,decimalA:n,decimalB:i}){let r=e.totalSellA.sub(e.realA),o=e.totalFundRaisingB.sub(e.realB);return new x(e.virtualB.add(e.realB.add(o)).toString()).div(e.virtualA.sub(e.realA.add(r)).toString()).mul(10**(n-i))}static getInitParam({supply:e,totalFundRaising:n,totalSell:i,totalLockedAmount:r,migrateFee:o}){if(e.lte(i))throw Error("supply need gt total sell");let s=e.sub(i).sub(r);if(s.lte(new Me(0)))throw Error("supplyMinusSellLocked <= 0");let a=n.sub(o);if(a.lte(new Me(0)))throw Error("tfMinusMf <= 0");let c=a.mul(i).mul(i).div(s),u=a.mul(i).div(s).sub(n);if(u.lt(new Me(0)))throw Error("supply/totalSell/totalLockedAmount diff too high");let l=c.div(u),m=n.mul(n).div(u);if(l.lt(new Me(0))||m.lt(new Me(0)))throw Error("invalid input 0");return{a:l,b:m,c:i}}static buyExactIn({poolInfo:e,amount:n}){return this.getAmountOut({amountIn:n,inputReserve:e.virtualB.add(e.realB),outputReserve:e.virtualA.sub(e.realA)})}static buyExactOut({poolInfo:e,amount:n}){return this.getAmountIn({amountOut:n,inputReserve:e.virtualB.add(e.realB),outputReserve:e.virtualA.sub(e.realA)})}static sellExactIn({poolInfo:e,amount:n}){return this.getAmountOut({amountIn:n,inputReserve:e.virtualA.sub(e.realA),outputReserve:e.virtualB.add(e.realB)})}static sellExactOut({poolInfo:e,amount:n}){return this.getAmountIn({amountOut:n,inputReserve:e.virtualA.sub(e.realA),outputReserve:e.virtualB.add(e.realB)})}static getAmountOut({amountIn:e,inputReserve:n,outputReserve:i}){let r=e.mul(i),o=n.add(e);return r.div(o)}static getAmountIn({amountOut:e,inputReserve:n,outputReserve:i}){let r=n.mul(e),o=i.sub(e);return Ye(r,o)}};import Ln from"bn.js";var tt=class extends pe{static getPoolInitPriceByPool({poolInfo:e,decimalA:n,decimalB:i}){return new x(e.virtualB.toString()).div(e.virtualA.toString()).mul(10**(n-i))}static getPoolInitPriceByInit({a:e,b:n,decimalA:i,decimalB:r}){return new x(n.toString()).div(e.toString()).mul(10**(i-r))}static getPoolPrice({poolInfo:e,decimalA:n,decimalB:i}){return new x(e.virtualB.toString()).div(e.virtualA.toString()).mul(10**(n-i))}static getPoolEndPrice({supply:e,totalSell:n,totalLockedAmount:i,totalFundRaising:r,migrateFee:o,decimalA:s,decimalB:a}){return new x(r.sub(o).toString()).div(e.sub(n).sub(i).toString()).mul(10**(s-a))}static getPoolEndPriceReal({poolInfo:e,decimalA:n,decimalB:i}){let r=e.totalSellA.sub(e.realA),o=e.totalFundRaisingB.sub(e.realB);return new x(e.virtualB.add(e.realB).add(o).toString()).div(e.virtualA.sub(e.realA).add(r).toString()).mul(10**(n-i))}static getInitParam({supply:e,totalFundRaising:n,totalSell:i,totalLockedAmount:r,migrateFee:o}){let s=e.sub(r);if(s.lte(new Ln(0)))throw Error("invalid input 1");let a=new Ln(2).mul(n).sub(o),u=n.mul(s).div(a);return{a:u,b:n,c:u}}static buyExactIn({poolInfo:e,amount:n}){return this.getAmountOut({amountIn:n,initInput:e.virtualB,initOutput:e.virtualA})}static buyExactOut({poolInfo:e,amount:n}){return this.getAmountIn({amountOut:n,initInput:e.virtualB,initOutput:e.virtualA})}static sellExactIn({poolInfo:e,amount:n}){return this.getAmountOut({amountIn:n,initInput:e.virtualA,initOutput:e.virtualB})}static sellExactOut({poolInfo:e,amount:n}){return this.getAmountIn({amountOut:n,initInput:e.virtualA,initOutput:e.virtualB})}static getAmountOut({amountIn:e,initInput:n,initOutput:i}){return i.mul(e).div(n)}static getAmountIn({amountOut:e,initInput:n,initOutput:i}){let r=n.mul(e);return Ye(r,i)}};import X from"bn.js";import Rn from"bn.js";var Fe=class{static _multipler(e){return new x(10).pow(e)}static getPrice({priceX64:e,decimalA:n,decimalB:i}){return new x(e.toString()).div(this._Q64).mul(this._multipler(n)).div(this._multipler(i))}static getPriceX64({price:e,decimalA:n,decimalB:i}){let r=e.mul(this._multipler(i)).div(this._multipler(n));return new Rn(r.mul(this._Q64).toFixed(0))}};Fe._Q64=new x(new Rn(1).shln(64).toString());var nt=class extends pe{static getPoolInitPriceByPool({poolInfo:e,decimalA:n,decimalB:i}){return new x(0)}static getPoolInitPriceByInit({a:e,b:n,decimalA:i,decimalB:r}){return new x(0)}static getPoolPrice({poolInfo:e,decimalA:n,decimalB:i}){return new x(e.virtualA.mul(e.realA).toString()).div(Fe._Q64).mul(10**(n-i))}static getPoolEndPrice({supply:e,totalSell:n,totalLockedAmount:i,totalFundRaising:r,migrateFee:o,decimalA:s,decimalB:a}){return new x(r.sub(o).toString()).div(e.sub(n).sub(i).toString()).mul(10**(s-a))}static getPoolEndPriceReal({poolInfo:e,decimalA:n,decimalB:i}){let r=e.totalSellA.sub(e.realA),o=e.totalFundRaisingB.sub(e.realB);return new x(e.virtualB.add(e.realB).add(o).toString()).div(e.virtualA.sub(e.realA).add(r).toString()).mul(10**(n-i))}static getInitParam({supply:e,totalFundRaising:n,totalSell:i,totalLockedAmount:r,migrateFee:o}){let s=e.sub(r);if(s.lte(new X(0)))throw Error("supplyMinusLocked need gt 0");let a=n.mul(new X(3)).sub(o),u=n.mul(new X(2)).mul(s).div(a),l=u.mul(u),m=n.mul(new X(2)).mul(ee).div(l);if(!m.gt(new X(0)))throw Error("a need gt 0");if(!St.gt(m))throw Error("a need lt u64 max");return{a:m,b:new X(0),c:u}}static buyExactIn({poolInfo:e,amount:n}){let i=e.realB.add(n),r=new X(2).mul(i).mul(ee).div(e.virtualA);return new X(new x(r.toString()).sqrt().toFixed(0)).sub(e.realA)}static buyExactOut({poolInfo:e,amount:n}){let i=e.realA.add(n),r=i.mul(i),{div:o,mod:s}=e.virtualA.mul(r).divmod(new X(2).mul(ee));return(s.isZero()?o:o.add(new X(1))).sub(e.realB)}static sellExactIn({poolInfo:e,amount:n}){let i=e.realA.sub(n),r=i.mul(i),{div:o,mod:s}=e.virtualA.mul(r).divmod(new X(2).mul(ee)),a=s.isZero()?o:o.add(new X(1));return e.realB.sub(a)}static sellExactOut({poolInfo:e,amount:n}){let i=e.realB.sub(n),r=new X(2).mul(i).mul(ee).div(e.virtualA),o=new X(new x(r.toString()).sqrt().toFixed(0));return e.realA.sub(o)}};var it=class{static getPoolCurvePointByPoolInfo({curveType:e,pointCount:n,poolInfo:i}){return this.getPoolCurvePointByInit({curveType:e,pointCount:n,supply:i.supply,totalFundRaising:i.totalFundRaisingB,totalSell:i.totalSellA,totalLockedAmount:i.vestingSchedule.totalLockedAmount,migrateFee:i.migrateFee,decimalA:i.mintDecimalsA,decimalB:i.mintDecimalsB})}static getPoolCurvePointByInit({curveType:e,pointCount:n,supply:i,totalFundRaising:r,totalSell:o,totalLockedAmount:s,migrateFee:a,decimalA:c,decimalB:u}){if(n<3)throw Error("point count < 3");let l=this.getCurve(e),m=l.getInitParam({supply:i,totalFundRaising:r,totalSell:o,totalLockedAmount:s,migrateFee:a}),d=l.getPoolInitPriceByInit(j(H({},m),{decimalA:c,decimalB:u})),b=r.div(new re(n-1)),h=new re(0),P=[{price:d,totalSellSupply:0}],{a:F,b:I}=m,v=h,B=h;for(let O=1;O<n;O++){let be=O!==n-1?b:r.sub(B),z=this.buyExactIn({poolInfo:{virtualA:F,virtualB:I,realA:v,realB:B,totalFundRaisingB:r,totalSellA:o},amountB:be,protocolFeeRate:h,platformFeeRate:h,curveType:e,shareFeeRate:h});v=v.add(z.amountA),B=B.add(z.amountB);let he=this.getPrice({poolInfo:{virtualA:F,virtualB:I,realA:v,realB:B},decimalA:c,decimalB:u,curveType:e});P.push({price:he,totalSellSupply:new x(v.toString()).div(10**c).toNumber()})}return P}static getPoolInitPriceByPool({poolInfo:e,decimalA:n,decimalB:i,curveType:r}){return this.getCurve(r).getPoolInitPriceByPool({poolInfo:e,decimalA:n,decimalB:i})}static getPoolInitPriceByInit({a:e,b:n,decimalA:i,decimalB:r,curveType:o}){return this.getCurve(o).getPoolInitPriceByInit({a:e,b:n,decimalA:i,decimalB:r})}static getPrice({poolInfo:e,curveType:n,decimalA:i,decimalB:r}){return this.getCurve(n).getPoolPrice({poolInfo:e,decimalA:i,decimalB:r})}static getEndPrice({poolInfo:e,curveType:n,decimalA:i,decimalB:r}){return this.getCurve(n).getPoolPrice({poolInfo:e,decimalA:i,decimalB:r})}static getPoolEndPriceReal({poolInfo:e,curveType:n,decimalA:i,decimalB:r}){return this.getCurve(n).getPoolEndPriceReal({poolInfo:e,decimalA:i,decimalB:r})}static checkParam({supply:e,totalFundRaising:n,totalSell:i,totalLockedAmount:r,decimals:o,config:s,migrateType:a}){if(Number(o)!==6)throw Error("decimals = 6");if(e.mul(s.maxLockRate).div(fe).lt(r))throw Error("total lock amount gte max lock amount");if(e.lt(s.minSupplyA.mul(new re(10**o))))throw Error("supply lt min supply");let u=e.mul(s.minSellRateA).div(fe);if(i.lt(u))throw Error("invalid input");if(n.lt(s.minFundRaisingB))throw Error("total fund raising lt min fund raising");let l=e.sub(i).sub(r),m=e.mul(s.minMigrateRateA).div(fe);if(l.lt(m))throw Error("migrate lt min migrate amount");let d=e.sub(i).sub(r),b=new re(new x(d.mul(n).toString()).sqrt().toFixed(0));if(a==="amm"){let h=new re(10).pow(new re(o));if(b.lte(h))throw Error("check migrate lp error")}else if(a==="cpmm"){let h=new re(100);if(b.lte(h))throw Error("check migrate lp error")}else throw Error("migrate type error")}static buyExactIn({poolInfo:e,amountB:n,protocolFeeRate:i,platformFeeRate:r,curveType:o,shareFeeRate:s}){let a=i.add(s).add(r),c=this.calculateFee({amount:n,feeRate:a}),u=n.sub(c),l=this.getCurve(o),m=l.buyExactIn({poolInfo:e,amount:u}),d=e.totalSellA.sub(e.realA),b,h,P;if(m.gt(d)){b=d;let I=l.buyExactOut({poolInfo:e,amount:b});h=this.calculatePreFee({postFeeAmount:I,feeRate:a}),P=h.sub(I)}else b=m,h=n,P=c;let F=this.splitFee({totalFee:P,protocolFeeRate:i,platformFeeRate:r,shareFeeRate:s});return{amountA:b,amountB:h,splitFee:F}}static buyExactOut({poolInfo:e,amountA:n,protocolFeeRate:i,platformFeeRate:r,curveType:o,shareFeeRate:s}){let a=e.totalSellA.sub(e.realA),c=n;n.gt(a)&&(c=a);let l=this.getCurve(o).buyExactOut({poolInfo:e,amount:n}),m=i.add(s).add(r),d=this.calculatePreFee({postFeeAmount:l,feeRate:m}),b=d.sub(l),h=this.splitFee({totalFee:b,protocolFeeRate:i,platformFeeRate:r,shareFeeRate:s});return{amountA:c,amountB:d,splitFee:h}}static sellExactIn({poolInfo:e,amountA:n,protocolFeeRate:i,platformFeeRate:r,curveType:o,shareFeeRate:s}){let c=this.getCurve(o).sellExactIn({poolInfo:e,amount:n}),u=this.calculateFee({amount:c,feeRate:i.add(s).add(r)}),l=this.splitFee({totalFee:u,protocolFeeRate:i,platformFeeRate:r,shareFeeRate:s});return{amountA:n,amountB:c.sub(u),splitFee:l}}static sellExactOut({poolInfo:e,amountB:n,protocolFeeRate:i,platformFeeRate:r,curveType:o,shareFeeRate:s}){let a=i.add(s).add(r),c=this.calculatePreFee({postFeeAmount:n,feeRate:a});if(e.realB.lt(c))throw Error("Insufficient liquidity");let u=c.sub(n),m=it.getCurve(o).sellExactOut({poolInfo:e,amount:c});if(m.gt(e.realA))throw Error();let d=this.splitFee({totalFee:u,protocolFeeRate:i,platformFeeRate:r,shareFeeRate:s});return{amountA:m,amountB:n,splitFee:d}}static splitFee({totalFee:e,protocolFeeRate:n,platformFeeRate:i,shareFeeRate:r}){let o=n.add(i).add(r),s=o.isZero()?new re(0):e.mul(i).div(o),a=o.isZero()?new re(0):e.mul(r).div(o),c=e.sub(s).sub(a);return{platformFee:s,shareFee:a,protocolFee:c}}static calculateFee({amount:e,feeRate:n}){return on(e,n,fe)}static calculatePreFee({postFeeAmount:e,feeRate:n}){if(n.isZero())return e;let i=e.mul(fe),r=fe.sub(n);return i.add(r).sub(new re(1)).div(r)}static getCurve(e){switch(e){case 0:return et;case 1:return tt;case 2:return nt}throw Error("find curve error")}};export{it as Curve};
2
2
  //# sourceMappingURL=curve.mjs.map
@@ -2,7 +2,7 @@ import BN__default from 'bn.js';
2
2
  import Decimal from 'decimal.js';
3
3
  import { LaunchpadPoolInfo } from '../type.js';
4
4
  import '@solana/web3.js';
5
- import '../../../api-24bf4058.js';
5
+ import '../../../api-0017263f.js';
6
6
  import 'axios';
7
7
  import '../../../solana/type.js';
8
8
  import '@solana/spl-token';
@@ -3,7 +3,7 @@ import Decimal from 'decimal.js';
3
3
  import { CurveBase, PoolBaseAmount } from './curveBase.js';
4
4
  import { LaunchpadPoolInfo } from '../type.js';
5
5
  import '@solana/web3.js';
6
- import '../../../api-24bf4058.js';
6
+ import '../../../api-0017263f.js';
7
7
  import 'axios';
8
8
  import '../../../solana/type.js';
9
9
  import '@solana/spl-token';
@@ -3,7 +3,7 @@ import Decimal from 'decimal.js';
3
3
  import { LaunchpadPoolInfo } from '../type.js';
4
4
  import { CurveBase, PoolBaseAmount } from './curveBase.js';
5
5
  import '@solana/web3.js';
6
- import '../../../api-24bf4058.js';
6
+ import '../../../api-0017263f.js';
7
7
  import 'axios';
8
8
  import '../../../solana/type.js';
9
9
  import '@solana/spl-token';