UNPKG

@raydium-io/raydium-sdk-v2

Version:

An SDK for building applications on top of Raydium.

2 lines 3.1 kB
import N from"bn.js";import R from"bn.js";import q from"decimal.js";import e from"bn.js";var l=new e(1).shln(64);var b=new e(1).shln(128),m=new e(1).shln(64).subn(1),E=new e(1).shln(128).subn(1);var O=new e("4295048016"),y=new e("79226673521066979257578248091"),a=new e("59543866431248"),M=new e("184467440737095516"),v=new e("15793534762490258745");var D=new e("18446743708227953217"),g=[{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 I=new e(0),T=new e(1),k=new e(-1);var F=new e("18446744073700000000");function B(d,o,r){if(r.isZero())throw new Error("Division by zero");return d.mul(o).div(r)}var K=new R(1).shln(256).subn(1);function n(d,o){return d.add(b).sub(o).mod(b)}var G=class{static getfeeGrowthInside(o,r,u){let s=new N(0),f=new N(0);o.tickCurrent>=r.tick?(s=r.feeGrowthOutsideX64A,f=r.feeGrowthOutsideX64B):(s=n(o.feeGrowthGlobalX64A,r.feeGrowthOutsideX64A),f=n(o.feeGrowthGlobalX64B,r.feeGrowthOutsideX64B));let t=new N(0),i=new N(0);o.tickCurrent<u.tick?(t=u.feeGrowthOutsideX64A,i=u.feeGrowthOutsideX64B):(t=n(o.feeGrowthGlobalX64A,u.feeGrowthOutsideX64A),i=n(o.feeGrowthGlobalX64B,u.feeGrowthOutsideX64B));let c=n(n(o.feeGrowthGlobalX64A,s),t),w=n(n(o.feeGrowthGlobalX64B,f),i);return{feeGrowthInsideX64A:c,feeGrowthInsideBX64:w}}static GetPositionFees(o,r,u,s){let{feeGrowthInsideX64A:f,feeGrowthInsideBX64:t}=this.getfeeGrowthInside(o,u,s),i=B(n(f,r.feeGrowthInsideLastX64A),r.liquidity,l),c=r.tokenFeesOwedA.add(i),w=B(n(t,r.feeGrowthInsideLastX64B),r.liquidity,l),h=r.tokenFeesOwedB.add(w);return{tokenFeeAmountA:c,tokenFeeAmountB:h}}static GetPositionRewards(o,r,u,s){let f=[],t=this.getRewardGrowthInside(o.tickCurrent,u,s,o.rewardInfos);for(let i=0;i<t.length;i++){let c=t[i],w=r.rewardInfos[i],h=n(c,w.growthInsideLastX64),A=B(h,r.liquidity,l),x=w.rewardAmountOwed.add(A);f.push(x)}return f}static getRewardGrowthInside(o,r,u,s){let f=[];for(let t=0;t<s.length;t++){let i=new N(0);r.liquidityGross.eqn(0)?i=s[t].growthGlobalX64:o<r.tick?i=n(s[t].growthGlobalX64,r.rewardGrowthsOutsideX64[t]):i=r.rewardGrowthsOutsideX64[t];let c=new N(0);u.liquidityGross.eqn(0)||(o<u.tick?c=u.rewardGrowthsOutsideX64[t]:c=n(s[t].growthGlobalX64,u.rewardGrowthsOutsideX64[t])),f.push(n(n(s[t].growthGlobalX64,i),c))}return f}};export{G as PositionUtils}; //# sourceMappingURL=position.mjs.map