@crypticdot/defituna-client 3.1.7 → 3.1.9

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.
package/dist/index.js CHANGED
@@ -10401,19 +10401,18 @@ function getDecreaseSpotPositionQuote(args) {
10401
10401
  let newPositionToken = positionToken;
10402
10402
  let decreasePercent;
10403
10403
  const price = (0, import_fusionamm_core4.sqrtPriceToPrice)(fusionPool.sqrtPrice, 1, 1);
10404
- if (decreaseAmount <= positionAmount || reduceOnly) {
10405
- let decreaseAmountInPositionToken;
10406
- if (collateralToken == positionToken) {
10407
- decreaseAmountInPositionToken = decreaseAmount;
10408
- } else {
10409
- decreaseAmountInPositionToken = BigInt(
10410
- Math.floor(collateralToken == 0 /* A */ ? Number(decreaseAmount) * price : Number(decreaseAmount) / price)
10411
- );
10412
- }
10404
+ let decreaseAmountInPositionToken = collateralToken == positionToken ? decreaseAmount : BigInt(
10405
+ Math.floor(collateralToken == 0 /* A */ ? Number(decreaseAmount) * price : Number(decreaseAmount) / price)
10406
+ );
10407
+ if (reduceOnly && decreaseAmountInPositionToken > positionAmount) {
10408
+ decreaseAmountInPositionToken = positionAmount;
10409
+ }
10410
+ if (decreaseAmountInPositionToken <= positionAmount) {
10413
10411
  decreasePercent = Math.min(
10414
10412
  Math.floor(Number(decreaseAmountInPositionToken) * HUNDRED_PERCENT / Number(positionAmount)),
10415
10413
  HUNDRED_PERCENT
10416
10414
  );
10415
+ estimatedAmount = positionAmount - decreaseAmountInPositionToken;
10417
10416
  if (collateralToken == positionToken) {
10418
10417
  if (positionDebt > 0) {
10419
10418
  const swapOut = BigInt(Math.floor(Number(positionDebt) * decreasePercent / HUNDRED_PERCENT));
@@ -10431,17 +10430,16 @@ function getDecreaseSpotPositionQuote(args) {
10431
10430
  tickArrays
10432
10431
  ).nextSqrtPrice;
10433
10432
  }
10434
- estimatedAmount = decreaseAmountInPositionToken <= positionAmount ? positionAmount - decreaseAmountInPositionToken : 0n;
10435
10433
  } else {
10436
10434
  decreasePercent = HUNDRED_PERCENT;
10437
10435
  const posTokenIsA = positionToken == 0 /* A */;
10438
10436
  newPositionToken = positionToken == 0 /* A */ ? 1 /* B */ : 0 /* A */;
10439
- const increaseAmount = decreaseAmount - positionAmount;
10437
+ const increaseAmount = decreaseAmountInPositionToken - positionAmount;
10440
10438
  if (positionToken == collateralToken) {
10441
10439
  estimatedAmount = BigInt(
10442
10440
  Math.floor(posTokenIsA ? Number(increaseAmount) * price : Number(increaseAmount) / price)
10443
10441
  );
10444
- collateral = leverage > 1 ? BigInt(Math.floor(Number(increaseAmount) / leverage)) : estimatedAmount;
10442
+ collateral = BigInt(Math.floor(Number(increaseAmount) / leverage));
10445
10443
  borrow = increaseAmount - collateral;
10446
10444
  if (positionDebt > 0) {
10447
10445
  const swapQuote = (0, import_fusionamm_core4.swapQuoteByOutputToken)(positionDebt, !posTokenIsA, 0, fusionPool, tickArrays);
package/dist/index.mjs CHANGED
@@ -10570,19 +10570,18 @@ function getDecreaseSpotPositionQuote(args) {
10570
10570
  let newPositionToken = positionToken;
10571
10571
  let decreasePercent;
10572
10572
  const price = sqrtPriceToPrice(fusionPool.sqrtPrice, 1, 1);
10573
- if (decreaseAmount <= positionAmount || reduceOnly) {
10574
- let decreaseAmountInPositionToken;
10575
- if (collateralToken == positionToken) {
10576
- decreaseAmountInPositionToken = decreaseAmount;
10577
- } else {
10578
- decreaseAmountInPositionToken = BigInt(
10579
- Math.floor(collateralToken == 0 /* A */ ? Number(decreaseAmount) * price : Number(decreaseAmount) / price)
10580
- );
10581
- }
10573
+ let decreaseAmountInPositionToken = collateralToken == positionToken ? decreaseAmount : BigInt(
10574
+ Math.floor(collateralToken == 0 /* A */ ? Number(decreaseAmount) * price : Number(decreaseAmount) / price)
10575
+ );
10576
+ if (reduceOnly && decreaseAmountInPositionToken > positionAmount) {
10577
+ decreaseAmountInPositionToken = positionAmount;
10578
+ }
10579
+ if (decreaseAmountInPositionToken <= positionAmount) {
10582
10580
  decreasePercent = Math.min(
10583
10581
  Math.floor(Number(decreaseAmountInPositionToken) * HUNDRED_PERCENT / Number(positionAmount)),
10584
10582
  HUNDRED_PERCENT
10585
10583
  );
10584
+ estimatedAmount = positionAmount - decreaseAmountInPositionToken;
10586
10585
  if (collateralToken == positionToken) {
10587
10586
  if (positionDebt > 0) {
10588
10587
  const swapOut = BigInt(Math.floor(Number(positionDebt) * decreasePercent / HUNDRED_PERCENT));
@@ -10600,17 +10599,16 @@ function getDecreaseSpotPositionQuote(args) {
10600
10599
  tickArrays
10601
10600
  ).nextSqrtPrice;
10602
10601
  }
10603
- estimatedAmount = decreaseAmountInPositionToken <= positionAmount ? positionAmount - decreaseAmountInPositionToken : 0n;
10604
10602
  } else {
10605
10603
  decreasePercent = HUNDRED_PERCENT;
10606
10604
  const posTokenIsA = positionToken == 0 /* A */;
10607
10605
  newPositionToken = positionToken == 0 /* A */ ? 1 /* B */ : 0 /* A */;
10608
- const increaseAmount = decreaseAmount - positionAmount;
10606
+ const increaseAmount = decreaseAmountInPositionToken - positionAmount;
10609
10607
  if (positionToken == collateralToken) {
10610
10608
  estimatedAmount = BigInt(
10611
10609
  Math.floor(posTokenIsA ? Number(increaseAmount) * price : Number(increaseAmount) / price)
10612
10610
  );
10613
- collateral = leverage > 1 ? BigInt(Math.floor(Number(increaseAmount) / leverage)) : estimatedAmount;
10611
+ collateral = BigInt(Math.floor(Number(increaseAmount) / leverage));
10614
10612
  borrow = increaseAmount - collateral;
10615
10613
  if (positionDebt > 0) {
10616
10614
  const swapQuote = swapQuoteByOutputToken(positionDebt, !posTokenIsA, 0, fusionPool, tickArrays);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@crypticdot/defituna-client",
3
3
  "description": "Typescript client to interact with DefiTuna's on-chain program.",
4
- "version": "3.1.7",
4
+ "version": "3.1.9",
5
5
  "private": false,
6
6
  "license": "SEE LICENSE IN LICENSE",
7
7
  "main": "./dist/index.js",