@crypticdot/defituna-api 1.6.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -46,6 +46,7 @@ var import_snakecase_keys = __toESM(require("snakecase-keys"));
46
46
  // src/client/schemas.ts
47
47
  var schemas_exports = {};
48
48
  __export(schemas_exports, {
49
+ CloseSpotPositionQuote: () => CloseSpotPositionQuote,
49
50
  DecreaseSpotPositionQuote: () => DecreaseSpotPositionQuote,
50
51
  FeesStatsGroup: () => FeesStatsGroup,
51
52
  IncreaseSpotPositionQuote: () => IncreaseSpotPositionQuote,
@@ -87,6 +88,7 @@ __export(schemas_exports, {
87
88
  PoolSwap: () => PoolSwap,
88
89
  PoolSwapNotification: () => PoolSwapNotification,
89
90
  PoolTicks: () => PoolTicks,
91
+ ShortPoolPriceUpdate: () => ShortPoolPriceUpdate,
90
92
  StakingLeaderboardPage: () => StakingLeaderboardPage,
91
93
  StakingLeaderboardPosition: () => StakingLeaderboardPosition,
92
94
  StakingPosition: () => StakingPosition,
@@ -96,6 +98,8 @@ __export(schemas_exports, {
96
98
  StakingPositionNotification: () => StakingPositionNotification,
97
99
  StakingRevenueStatsGroup: () => StakingRevenueStatsGroup,
98
100
  StakingTreasury: () => StakingTreasury,
101
+ StateSnapshot: () => StateSnapshot,
102
+ StateSnapshotNotification: () => StateSnapshotNotification,
99
103
  SwapQuoteByInput: () => SwapQuoteByInput,
100
104
  SwapQuoteByOutput: () => SwapQuoteByOutput,
101
105
  Tick: () => Tick,
@@ -669,7 +673,7 @@ var IncreaseSpotPositionQuote = import_zod.z.object({
669
673
  uiLiquidationPrice: import_zod.z.nullable(import_zod.z.number())
670
674
  });
671
675
  var DecreaseSpotPositionQuote = import_zod.z.object({
672
- /** Position decrease percentage */
676
+ /** Confirmed position decrease percentage (100% = 1.0) */
673
677
  decreasePercent: import_zod.z.number(),
674
678
  /** The maximum acceptable swap input amount for position decrease according to the provided slippage
675
679
  * (if collateral_token == position_token) OR the minimum swap output amount (if collateral_token != position_token).
@@ -677,11 +681,25 @@ var DecreaseSpotPositionQuote = import_zod.z.object({
677
681
  requiredSwapAmount: import_zod.z.coerce.bigint(),
678
682
  /** Estimated total amount of the adjusted position */
679
683
  estimatedAmount: import_zod.z.coerce.bigint(),
684
+ /** Estimated amount of the withdrawn collateral */
685
+ estimatedWithdrawnCollateral: import_zod.z.coerce.bigint(),
680
686
  /** Price impact in percents */
681
687
  priceImpact: import_zod.z.number(),
682
688
  /** Liquidation price */
683
689
  uiLiquidationPrice: import_zod.z.nullable(import_zod.z.number())
684
690
  });
691
+ var CloseSpotPositionQuote = import_zod.z.object({
692
+ /** Position decrease percentage */
693
+ decreasePercent: import_zod.z.number(),
694
+ /** The maximum acceptable swap input amount for position decrease according to the provided slippage
695
+ * (if collateral_token == position_token) OR the minimum swap output amount (if collateral_token != position_token).
696
+ */
697
+ requiredSwapAmount: import_zod.z.coerce.bigint(),
698
+ /** Estimated amount of the withdrawn collateral */
699
+ estimatedWithdrawnCollateral: import_zod.z.coerce.bigint(),
700
+ /** Price impact in percents */
701
+ priceImpact: import_zod.z.number()
702
+ });
685
703
  var SwapQuoteByInput = import_zod.z.object({
686
704
  estimatedAmountOut: import_zod.z.coerce.bigint(),
687
705
  minAmountOut: import_zod.z.coerce.bigint(),
@@ -698,6 +716,19 @@ var SwapQuoteByOutput = import_zod.z.object({
698
716
  /** Price impact in percents */
699
717
  priceImpact: import_zod.z.number()
700
718
  });
719
+ var ShortPoolPriceUpdate = import_zod.z.object({
720
+ price: import_zod.z.number(),
721
+ uiPrice: import_zod.z.number(),
722
+ sqrtPrice: import_zod.z.coerce.bigint()
723
+ });
724
+ var StateSnapshot = import_zod.z.object({
725
+ slot: import_zod.z.coerce.bigint(),
726
+ blockTime: import_zod.z.coerce.date(),
727
+ poolPrices: import_zod.z.optional(import_zod.z.map(import_zod.z.string(), ShortPoolPriceUpdate)),
728
+ tunaSpotPositions: import_zod.z.optional(import_zod.z.array(TunaSpotPosition)),
729
+ tunaLpPositions: import_zod.z.optional(import_zod.z.array(TunaPosition)),
730
+ fusionLimitOrders: import_zod.z.optional(import_zod.z.array(LimitOrder))
731
+ });
701
732
  var LimitOrderQuoteByInput = import_zod.z.object({
702
733
  amountOut: import_zod.z.coerce.bigint()
703
734
  });
@@ -731,6 +762,7 @@ var LimitOrderNotification = createNotificationSchema(LimitOrder);
731
762
  var TradeHistoryEntryNotification = createNotificationSchema(TradeHistoryEntry);
732
763
  var OrderHistoryEntryNotification = createNotificationSchema(OrderHistoryEntry);
733
764
  var StakingPositionNotification = createNotificationSchema(StakingPosition);
765
+ var StateSnapshotNotification = createNotificationSchema(StateSnapshot);
734
766
 
735
767
  // src/client/client.ts
736
768
  var DEFAULT_TIMEOUT = 5e3;
@@ -1136,6 +1168,24 @@ var TunaApiClient = class {
1136
1168
  signal: config?.abortSignal
1137
1169
  });
1138
1170
  }
1171
+ async getCloseSpotPositionQuote(args, config) {
1172
+ const { market, decreasePercent, collateralToken, positionToken, positionAmount, positionDebt, slippageTolerance } = args;
1173
+ let query = {
1174
+ market,
1175
+ decrease_percent: decreasePercent,
1176
+ collateral_token: collateralToken,
1177
+ position_token: positionToken,
1178
+ position_amount: positionAmount.toString(),
1179
+ position_debt: positionDebt.toString()
1180
+ };
1181
+ if (slippageTolerance) {
1182
+ query.slippage_tolerance = slippageTolerance;
1183
+ }
1184
+ const url = this.appendUrlSearchParams(this.buildURL(`quotes/close-spot-position`), query);
1185
+ return await this.httpRequest(url, CloseSpotPositionQuote, {
1186
+ signal: config?.abortSignal
1187
+ });
1188
+ }
1139
1189
  async getTradableAmount(args, config) {
1140
1190
  const { market, collateralToken, positionToken, availableBalance, leverage, positionAmount, increase } = args;
1141
1191
  const url = this.appendUrlSearchParams(this.buildURL(`quotes/tradable-amount`), {
package/dist/index.mjs CHANGED
@@ -11,6 +11,7 @@ import snakecaseKeys from "snakecase-keys";
11
11
  // src/client/schemas.ts
12
12
  var schemas_exports = {};
13
13
  __export(schemas_exports, {
14
+ CloseSpotPositionQuote: () => CloseSpotPositionQuote,
14
15
  DecreaseSpotPositionQuote: () => DecreaseSpotPositionQuote,
15
16
  FeesStatsGroup: () => FeesStatsGroup,
16
17
  IncreaseSpotPositionQuote: () => IncreaseSpotPositionQuote,
@@ -52,6 +53,7 @@ __export(schemas_exports, {
52
53
  PoolSwap: () => PoolSwap,
53
54
  PoolSwapNotification: () => PoolSwapNotification,
54
55
  PoolTicks: () => PoolTicks,
56
+ ShortPoolPriceUpdate: () => ShortPoolPriceUpdate,
55
57
  StakingLeaderboardPage: () => StakingLeaderboardPage,
56
58
  StakingLeaderboardPosition: () => StakingLeaderboardPosition,
57
59
  StakingPosition: () => StakingPosition,
@@ -61,6 +63,8 @@ __export(schemas_exports, {
61
63
  StakingPositionNotification: () => StakingPositionNotification,
62
64
  StakingRevenueStatsGroup: () => StakingRevenueStatsGroup,
63
65
  StakingTreasury: () => StakingTreasury,
66
+ StateSnapshot: () => StateSnapshot,
67
+ StateSnapshotNotification: () => StateSnapshotNotification,
64
68
  SwapQuoteByInput: () => SwapQuoteByInput,
65
69
  SwapQuoteByOutput: () => SwapQuoteByOutput,
66
70
  Tick: () => Tick,
@@ -634,7 +638,7 @@ var IncreaseSpotPositionQuote = z.object({
634
638
  uiLiquidationPrice: z.nullable(z.number())
635
639
  });
636
640
  var DecreaseSpotPositionQuote = z.object({
637
- /** Position decrease percentage */
641
+ /** Confirmed position decrease percentage (100% = 1.0) */
638
642
  decreasePercent: z.number(),
639
643
  /** The maximum acceptable swap input amount for position decrease according to the provided slippage
640
644
  * (if collateral_token == position_token) OR the minimum swap output amount (if collateral_token != position_token).
@@ -642,11 +646,25 @@ var DecreaseSpotPositionQuote = z.object({
642
646
  requiredSwapAmount: z.coerce.bigint(),
643
647
  /** Estimated total amount of the adjusted position */
644
648
  estimatedAmount: z.coerce.bigint(),
649
+ /** Estimated amount of the withdrawn collateral */
650
+ estimatedWithdrawnCollateral: z.coerce.bigint(),
645
651
  /** Price impact in percents */
646
652
  priceImpact: z.number(),
647
653
  /** Liquidation price */
648
654
  uiLiquidationPrice: z.nullable(z.number())
649
655
  });
656
+ var CloseSpotPositionQuote = z.object({
657
+ /** Position decrease percentage */
658
+ decreasePercent: z.number(),
659
+ /** The maximum acceptable swap input amount for position decrease according to the provided slippage
660
+ * (if collateral_token == position_token) OR the minimum swap output amount (if collateral_token != position_token).
661
+ */
662
+ requiredSwapAmount: z.coerce.bigint(),
663
+ /** Estimated amount of the withdrawn collateral */
664
+ estimatedWithdrawnCollateral: z.coerce.bigint(),
665
+ /** Price impact in percents */
666
+ priceImpact: z.number()
667
+ });
650
668
  var SwapQuoteByInput = z.object({
651
669
  estimatedAmountOut: z.coerce.bigint(),
652
670
  minAmountOut: z.coerce.bigint(),
@@ -663,6 +681,19 @@ var SwapQuoteByOutput = z.object({
663
681
  /** Price impact in percents */
664
682
  priceImpact: z.number()
665
683
  });
684
+ var ShortPoolPriceUpdate = z.object({
685
+ price: z.number(),
686
+ uiPrice: z.number(),
687
+ sqrtPrice: z.coerce.bigint()
688
+ });
689
+ var StateSnapshot = z.object({
690
+ slot: z.coerce.bigint(),
691
+ blockTime: z.coerce.date(),
692
+ poolPrices: z.optional(z.map(z.string(), ShortPoolPriceUpdate)),
693
+ tunaSpotPositions: z.optional(z.array(TunaSpotPosition)),
694
+ tunaLpPositions: z.optional(z.array(TunaPosition)),
695
+ fusionLimitOrders: z.optional(z.array(LimitOrder))
696
+ });
666
697
  var LimitOrderQuoteByInput = z.object({
667
698
  amountOut: z.coerce.bigint()
668
699
  });
@@ -696,6 +727,7 @@ var LimitOrderNotification = createNotificationSchema(LimitOrder);
696
727
  var TradeHistoryEntryNotification = createNotificationSchema(TradeHistoryEntry);
697
728
  var OrderHistoryEntryNotification = createNotificationSchema(OrderHistoryEntry);
698
729
  var StakingPositionNotification = createNotificationSchema(StakingPosition);
730
+ var StateSnapshotNotification = createNotificationSchema(StateSnapshot);
699
731
 
700
732
  // src/client/client.ts
701
733
  var DEFAULT_TIMEOUT = 5e3;
@@ -1101,6 +1133,24 @@ var TunaApiClient = class {
1101
1133
  signal: config?.abortSignal
1102
1134
  });
1103
1135
  }
1136
+ async getCloseSpotPositionQuote(args, config) {
1137
+ const { market, decreasePercent, collateralToken, positionToken, positionAmount, positionDebt, slippageTolerance } = args;
1138
+ let query = {
1139
+ market,
1140
+ decrease_percent: decreasePercent,
1141
+ collateral_token: collateralToken,
1142
+ position_token: positionToken,
1143
+ position_amount: positionAmount.toString(),
1144
+ position_debt: positionDebt.toString()
1145
+ };
1146
+ if (slippageTolerance) {
1147
+ query.slippage_tolerance = slippageTolerance;
1148
+ }
1149
+ const url = this.appendUrlSearchParams(this.buildURL(`quotes/close-spot-position`), query);
1150
+ return await this.httpRequest(url, CloseSpotPositionQuote, {
1151
+ signal: config?.abortSignal
1152
+ });
1153
+ }
1104
1154
  async getTradableAmount(args, config) {
1105
1155
  const { market, collateralToken, positionToken, availableBalance, leverage, positionAmount, increase } = args;
1106
1156
  const url = this.appendUrlSearchParams(this.buildURL(`quotes/tradable-amount`), {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crypticdot/defituna-api",
3
- "version": "1.6.0",
3
+ "version": "1.8.0",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",