UNPKG

@raydium-io/raydium-sdk-v2

Version:

An SDK for building applications on top of Raydium.

2 lines 2.68 kB
import d from"bn.js";import a from"decimal.js";import e from"bn.js";var T=new e(1).shln(64),p=64,m=new e(1).shln(128),I=new e(1).shln(64).subn(1),R=new e(1).shln(128).subn(1);var O=new e("4295048016"),h=new e("79226673521066979257578248091"),g=new e("59543866431248"),M=new e("184467440737095516"),v=new e("15793534762490258745");var D=new e("18446743708227953217"),Z=[{bit:0,factor:new e("fffcb933bd6fb800",16)},{bit:1,factor:new e("fff97272373d4000",16)},{bit:2,factor:new e("fff2e50f5f657000",16)},{bit:3,factor:new e("ffe5caca7e10f000",16)},{bit:4,factor:new e("ffcb9843d60f7000",16)},{bit:5,factor:new e("ff973b41fa98e800",16)},{bit:6,factor:new e("ff2ea16466c9b000",16)},{bit:7,factor:new e("fe5dee046a9a3800",16)},{bit:8,factor:new e("fcbe86c7900bb000",16)},{bit:9,factor:new e("f987a7253ac65800",16)},{bit:10,factor:new e("f3392b0822bb6000",16)},{bit:11,factor:new e("e7159475a2caf000",16)},{bit:12,factor:new e("d097f3bdfd2f2000",16)},{bit:13,factor:new e("a9f746462d9f8000",16)},{bit:14,factor:new e("70d869a156f31c00",16)},{bit:15,factor:new e("31be135f97ed3200",16)},{bit:16,factor:new e("9aa508b5b85a500",16)},{bit:17,factor:new e("5d6af8dedc582c",16)},{bit:18,factor:new e("2216e584f5fa",16)}];var c=new e(0),N=new e(1),F=new e(-1);var C=new e("18446744073700000000");function w(u,r,n){if(n.isZero())throw new Error("Division by zero");return u.mul(r).div(n)}function B(u,r,n){if(n.isZero())throw new Error("Division by zero");let t=u.mul(r),i=t.div(n);return t.mod(n).isZero()?i:i.addn(1)}function E(u,r){return u.div(r).add(u.mod(r).isZero()?c:N)}var Q=new d(1).shln(256).subn(1);var b=class{static getNextSqrtPriceFromAmountARoundingUp(r,n,t,i){if(t.isZero())return r;let o=n.shln(p);if(i){let f=t.mul(r),s=o.add(f);if(s.gte(o))return B(o,r,s);let x=w(o,N,r);return B(o,N,x.add(t))}else{let f=t.mul(r);if(o.lte(f))throw new Error("Insufficient liquidity for token0 removal");let s=o.sub(f);return B(o,r,s)}}static getNextSqrtPriceFromAmountBRoundingDown(r,n,t,i){if(t.isZero())return r;if(i){let o=t.shln(p).div(n);return r.add(o)}else{let o=E(t.shln(p),n);return r.sub(o)}}static getNextSqrtPriceFromInput(r,n,t,i){if(!r.gt(c))throw Error("sqrtPriceX64.gt(BN_ZERO)");if(!n.gt(c))throw Error("liquidity.gt(BN_ZERO)");return i?this.getNextSqrtPriceFromAmountARoundingUp(r,n,t,!0):this.getNextSqrtPriceFromAmountBRoundingDown(r,n,t,!0)}static getNextSqrtPriceFromOutput(r,n,t,i){if(!r.gt(c))throw Error("sqrtPriceX64.gt(BN_ZERO)");if(!n.gt(c))throw Error("liquidity.gt(BN_ZERO)");return i?this.getNextSqrtPriceFromAmountBRoundingDown(r,n,t,!1):this.getNextSqrtPriceFromAmountARoundingUp(r,n,t,!1)}};export{b as SqrtPriceMath}; //# sourceMappingURL=sqrtPriceMath.mjs.map