@meteora-ag/zap-sdk 1.2.0-rc.4 → 1.2.0-rc.6

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.d.mts CHANGED
@@ -1716,6 +1716,7 @@ type GetZapInDammV2IndirectPoolParams = {
1716
1716
  slippageBps: number;
1717
1717
  jupiterQuoteToA: JupiterQuoteResponse | null;
1718
1718
  jupiterQuoteToB: JupiterQuoteResponse | null;
1719
+ forceTwoSidedWhenBothQuotes?: boolean;
1719
1720
  };
1720
1721
  declare enum ZapInDammV2PoolSwapRoute {
1721
1722
  Jupiter = "jupiter",
@@ -2020,6 +2021,7 @@ declare class Zap {
2020
2021
  private zapInDammV2;
2021
2022
  private resetOrInitializeLedgerAccount;
2022
2023
  private isJupiterQuoteableAmount;
2024
+ private getJupiterQuoteForAmount;
2023
2025
  private findMinimumJupiterQuoteableAmount;
2024
2026
  private zapInDlmmForInitializedPosition;
2025
2027
  private zapInDlmmForUninitializedPosition;
package/dist/index.d.ts CHANGED
@@ -1716,6 +1716,7 @@ type GetZapInDammV2IndirectPoolParams = {
1716
1716
  slippageBps: number;
1717
1717
  jupiterQuoteToA: JupiterQuoteResponse | null;
1718
1718
  jupiterQuoteToB: JupiterQuoteResponse | null;
1719
+ forceTwoSidedWhenBothQuotes?: boolean;
1719
1720
  };
1720
1721
  declare enum ZapInDammV2PoolSwapRoute {
1721
1722
  Jupiter = "jupiter",
@@ -2020,6 +2021,7 @@ declare class Zap {
2020
2021
  private zapInDammV2;
2021
2022
  private resetOrInitializeLedgerAccount;
2022
2023
  private isJupiterQuoteableAmount;
2024
+ private getJupiterQuoteForAmount;
2023
2025
  private findMinimumJupiterQuoteableAmount;
2024
2026
  private zapInDlmmForInitializedPosition;
2025
2027
  private zapInDlmmForUninitializedPosition;
package/dist/index.js CHANGED
@@ -3354,6 +3354,27 @@ var Zap = class {
3354
3354
  return quote !== null;
3355
3355
  });
3356
3356
  }
3357
+ getJupiterQuoteForAmount(inputMint, outputMint, amount, maxAccounts, slippageBps) {
3358
+ return __async(this, null, function* () {
3359
+ if (amount.isZero()) {
3360
+ return null;
3361
+ }
3362
+ return yield getJupiterQuote(
3363
+ inputMint,
3364
+ outputMint,
3365
+ amount,
3366
+ maxAccounts,
3367
+ slippageBps,
3368
+ false,
3369
+ true,
3370
+ true,
3371
+ {
3372
+ jupiterApiUrl: this.jupiterApiUrl,
3373
+ jupiterApiKey: this.jupiterApiKey
3374
+ }
3375
+ );
3376
+ });
3377
+ }
3357
3378
  findMinimumJupiterQuoteableAmount(inputMint, outputMint, maxAmount, maxAccounts, slippageBps) {
3358
3379
  return __async(this, null, function* () {
3359
3380
  if (maxAmount.isZero()) {
@@ -3757,7 +3778,8 @@ var Zap = class {
3757
3778
  maxTransferAmountExtendPercentage,
3758
3779
  slippageBps,
3759
3780
  jupiterQuoteToA,
3760
- jupiterQuoteToB
3781
+ jupiterQuoteToB,
3782
+ forceTwoSidedWhenBothQuotes = false
3761
3783
  } = params;
3762
3784
  const poolState = yield getDammV2Pool(this.connection, pool);
3763
3785
  const {
@@ -3942,6 +3964,32 @@ var Zap = class {
3942
3964
  )
3943
3965
  );
3944
3966
  let { swapAmountToA: adjustedSwapAmountToA, swapAmountToB } = splitIndirectSwapAmounts(amountIn, swapAmountToA);
3967
+ if (forceTwoSidedWhenBothQuotes && adjustedSwapAmountToA.isZero()) {
3968
+ const minQuoteableToA = yield this.findMinimumJupiterQuoteableAmount(
3969
+ inputTokenMint,
3970
+ tokenAMint,
3971
+ amountIn,
3972
+ maxAccounts,
3973
+ slippageBps
3974
+ );
3975
+ if (minQuoteableToA !== null && minQuoteableToA.gt(new import_anchor.BN(0)) && minQuoteableToA.lt(amountIn)) {
3976
+ adjustedSwapAmountToA = minQuoteableToA;
3977
+ swapAmountToB = amountIn.sub(adjustedSwapAmountToA);
3978
+ }
3979
+ }
3980
+ if (forceTwoSidedWhenBothQuotes && swapAmountToB.isZero()) {
3981
+ const minQuoteableToB = yield this.findMinimumJupiterQuoteableAmount(
3982
+ inputTokenMint,
3983
+ tokenBMint,
3984
+ amountIn,
3985
+ maxAccounts,
3986
+ slippageBps
3987
+ );
3988
+ if (minQuoteableToB !== null && minQuoteableToB.gt(new import_anchor.BN(0)) && minQuoteableToB.lt(amountIn)) {
3989
+ swapAmountToB = minQuoteableToB;
3990
+ adjustedSwapAmountToA = amountIn.sub(swapAmountToB);
3991
+ }
3992
+ }
3945
3993
  const quoteableA = yield this.isJupiterQuoteableAmount(
3946
3994
  inputTokenMint,
3947
3995
  tokenAMint,
@@ -3997,7 +4045,26 @@ var Zap = class {
3997
4045
  "Calculated zero swap amount for both token routes, unable to proceed"
3998
4046
  );
3999
4047
  }
4000
- if (!hasSwapToA) {
4048
+ const quoteToAForSwap = yield this.getJupiterQuoteForAmount(
4049
+ inputTokenMint,
4050
+ tokenAMint,
4051
+ adjustedSwapAmountToA,
4052
+ maxAccounts,
4053
+ slippageBps
4054
+ );
4055
+ const quoteToBForSwap = yield this.getJupiterQuoteForAmount(
4056
+ inputTokenMint,
4057
+ tokenBMint,
4058
+ swapAmountToB,
4059
+ maxAccounts,
4060
+ slippageBps
4061
+ );
4062
+ if (!hasSwapToA || quoteToAForSwap === null) {
4063
+ if (quoteToBForSwap === null) {
4064
+ throw new Error(
4065
+ `Failed to get Jupiter quote for swap from ${inputTokenMint.toBase58()} to ${tokenBMint.toBase58()}`
4066
+ );
4067
+ }
4001
4068
  const { transaction: swapToBTransaction2, quoteResponse: swapToBQuote2 } = yield buildJupiterSwapTransaction(
4002
4069
  user,
4003
4070
  inputTokenMint,
@@ -4005,7 +4072,7 @@ var Zap = class {
4005
4072
  swapAmountToB,
4006
4073
  maxAccounts,
4007
4074
  slippageBps,
4008
- void 0,
4075
+ quoteToBForSwap,
4009
4076
  {
4010
4077
  jupiterApiUrl: this.jupiterApiUrl,
4011
4078
  jupiterApiKey: this.jupiterApiKey
@@ -4043,7 +4110,12 @@ var Zap = class {
4043
4110
  }
4044
4111
  };
4045
4112
  }
4046
- if (!hasSwapToB) {
4113
+ if (!hasSwapToB || quoteToBForSwap === null) {
4114
+ if (quoteToAForSwap === null) {
4115
+ throw new Error(
4116
+ `Failed to get Jupiter quote for swap from ${inputTokenMint.toBase58()} to ${tokenAMint.toBase58()}`
4117
+ );
4118
+ }
4047
4119
  const { transaction: swapToATransaction2, quoteResponse: swapToAQuote2 } = yield buildJupiterSwapTransaction(
4048
4120
  user,
4049
4121
  inputTokenMint,
@@ -4051,7 +4123,7 @@ var Zap = class {
4051
4123
  adjustedSwapAmountToA,
4052
4124
  maxAccounts,
4053
4125
  slippageBps,
4054
- void 0,
4126
+ quoteToAForSwap,
4055
4127
  {
4056
4128
  jupiterApiUrl: this.jupiterApiUrl,
4057
4129
  jupiterApiKey: this.jupiterApiKey
@@ -4089,6 +4161,11 @@ var Zap = class {
4089
4161
  }
4090
4162
  };
4091
4163
  }
4164
+ if (quoteToAForSwap === null || quoteToBForSwap === null) {
4165
+ throw new Error(
4166
+ "Failed to get Jupiter quote for both token routes, unable to proceed"
4167
+ );
4168
+ }
4092
4169
  const { transaction: swapToATransaction, quoteResponse: swapToAQuote } = yield buildJupiterSwapTransaction(
4093
4170
  user,
4094
4171
  inputTokenMint,
@@ -4096,7 +4173,7 @@ var Zap = class {
4096
4173
  adjustedSwapAmountToA,
4097
4174
  maxAccounts,
4098
4175
  slippageBps,
4099
- void 0,
4176
+ quoteToAForSwap,
4100
4177
  {
4101
4178
  jupiterApiUrl: this.jupiterApiUrl,
4102
4179
  jupiterApiKey: this.jupiterApiKey
@@ -4109,7 +4186,7 @@ var Zap = class {
4109
4186
  swapAmountToB,
4110
4187
  maxAccounts,
4111
4188
  slippageBps,
4112
- void 0,
4189
+ quoteToBForSwap,
4113
4190
  {
4114
4191
  jupiterApiUrl: this.jupiterApiUrl,
4115
4192
  jupiterApiKey: this.jupiterApiKey
package/dist/index.mjs CHANGED
@@ -3333,6 +3333,27 @@ var Zap = class {
3333
3333
  return quote !== null;
3334
3334
  });
3335
3335
  }
3336
+ getJupiterQuoteForAmount(inputMint, outputMint, amount, maxAccounts, slippageBps) {
3337
+ return __async(this, null, function* () {
3338
+ if (amount.isZero()) {
3339
+ return null;
3340
+ }
3341
+ return yield getJupiterQuote(
3342
+ inputMint,
3343
+ outputMint,
3344
+ amount,
3345
+ maxAccounts,
3346
+ slippageBps,
3347
+ false,
3348
+ true,
3349
+ true,
3350
+ {
3351
+ jupiterApiUrl: this.jupiterApiUrl,
3352
+ jupiterApiKey: this.jupiterApiKey
3353
+ }
3354
+ );
3355
+ });
3356
+ }
3336
3357
  findMinimumJupiterQuoteableAmount(inputMint, outputMint, maxAmount, maxAccounts, slippageBps) {
3337
3358
  return __async(this, null, function* () {
3338
3359
  if (maxAmount.isZero()) {
@@ -3736,7 +3757,8 @@ var Zap = class {
3736
3757
  maxTransferAmountExtendPercentage,
3737
3758
  slippageBps,
3738
3759
  jupiterQuoteToA,
3739
- jupiterQuoteToB
3760
+ jupiterQuoteToB,
3761
+ forceTwoSidedWhenBothQuotes = false
3740
3762
  } = params;
3741
3763
  const poolState = yield getDammV2Pool(this.connection, pool);
3742
3764
  const {
@@ -3921,6 +3943,32 @@ var Zap = class {
3921
3943
  )
3922
3944
  );
3923
3945
  let { swapAmountToA: adjustedSwapAmountToA, swapAmountToB } = splitIndirectSwapAmounts(amountIn, swapAmountToA);
3946
+ if (forceTwoSidedWhenBothQuotes && adjustedSwapAmountToA.isZero()) {
3947
+ const minQuoteableToA = yield this.findMinimumJupiterQuoteableAmount(
3948
+ inputTokenMint,
3949
+ tokenAMint,
3950
+ amountIn,
3951
+ maxAccounts,
3952
+ slippageBps
3953
+ );
3954
+ if (minQuoteableToA !== null && minQuoteableToA.gt(new BN5(0)) && minQuoteableToA.lt(amountIn)) {
3955
+ adjustedSwapAmountToA = minQuoteableToA;
3956
+ swapAmountToB = amountIn.sub(adjustedSwapAmountToA);
3957
+ }
3958
+ }
3959
+ if (forceTwoSidedWhenBothQuotes && swapAmountToB.isZero()) {
3960
+ const minQuoteableToB = yield this.findMinimumJupiterQuoteableAmount(
3961
+ inputTokenMint,
3962
+ tokenBMint,
3963
+ amountIn,
3964
+ maxAccounts,
3965
+ slippageBps
3966
+ );
3967
+ if (minQuoteableToB !== null && minQuoteableToB.gt(new BN5(0)) && minQuoteableToB.lt(amountIn)) {
3968
+ swapAmountToB = minQuoteableToB;
3969
+ adjustedSwapAmountToA = amountIn.sub(swapAmountToB);
3970
+ }
3971
+ }
3924
3972
  const quoteableA = yield this.isJupiterQuoteableAmount(
3925
3973
  inputTokenMint,
3926
3974
  tokenAMint,
@@ -3976,7 +4024,26 @@ var Zap = class {
3976
4024
  "Calculated zero swap amount for both token routes, unable to proceed"
3977
4025
  );
3978
4026
  }
3979
- if (!hasSwapToA) {
4027
+ const quoteToAForSwap = yield this.getJupiterQuoteForAmount(
4028
+ inputTokenMint,
4029
+ tokenAMint,
4030
+ adjustedSwapAmountToA,
4031
+ maxAccounts,
4032
+ slippageBps
4033
+ );
4034
+ const quoteToBForSwap = yield this.getJupiterQuoteForAmount(
4035
+ inputTokenMint,
4036
+ tokenBMint,
4037
+ swapAmountToB,
4038
+ maxAccounts,
4039
+ slippageBps
4040
+ );
4041
+ if (!hasSwapToA || quoteToAForSwap === null) {
4042
+ if (quoteToBForSwap === null) {
4043
+ throw new Error(
4044
+ `Failed to get Jupiter quote for swap from ${inputTokenMint.toBase58()} to ${tokenBMint.toBase58()}`
4045
+ );
4046
+ }
3980
4047
  const { transaction: swapToBTransaction2, quoteResponse: swapToBQuote2 } = yield buildJupiterSwapTransaction(
3981
4048
  user,
3982
4049
  inputTokenMint,
@@ -3984,7 +4051,7 @@ var Zap = class {
3984
4051
  swapAmountToB,
3985
4052
  maxAccounts,
3986
4053
  slippageBps,
3987
- void 0,
4054
+ quoteToBForSwap,
3988
4055
  {
3989
4056
  jupiterApiUrl: this.jupiterApiUrl,
3990
4057
  jupiterApiKey: this.jupiterApiKey
@@ -4022,7 +4089,12 @@ var Zap = class {
4022
4089
  }
4023
4090
  };
4024
4091
  }
4025
- if (!hasSwapToB) {
4092
+ if (!hasSwapToB || quoteToBForSwap === null) {
4093
+ if (quoteToAForSwap === null) {
4094
+ throw new Error(
4095
+ `Failed to get Jupiter quote for swap from ${inputTokenMint.toBase58()} to ${tokenAMint.toBase58()}`
4096
+ );
4097
+ }
4026
4098
  const { transaction: swapToATransaction2, quoteResponse: swapToAQuote2 } = yield buildJupiterSwapTransaction(
4027
4099
  user,
4028
4100
  inputTokenMint,
@@ -4030,7 +4102,7 @@ var Zap = class {
4030
4102
  adjustedSwapAmountToA,
4031
4103
  maxAccounts,
4032
4104
  slippageBps,
4033
- void 0,
4105
+ quoteToAForSwap,
4034
4106
  {
4035
4107
  jupiterApiUrl: this.jupiterApiUrl,
4036
4108
  jupiterApiKey: this.jupiterApiKey
@@ -4068,6 +4140,11 @@ var Zap = class {
4068
4140
  }
4069
4141
  };
4070
4142
  }
4143
+ if (quoteToAForSwap === null || quoteToBForSwap === null) {
4144
+ throw new Error(
4145
+ "Failed to get Jupiter quote for both token routes, unable to proceed"
4146
+ );
4147
+ }
4071
4148
  const { transaction: swapToATransaction, quoteResponse: swapToAQuote } = yield buildJupiterSwapTransaction(
4072
4149
  user,
4073
4150
  inputTokenMint,
@@ -4075,7 +4152,7 @@ var Zap = class {
4075
4152
  adjustedSwapAmountToA,
4076
4153
  maxAccounts,
4077
4154
  slippageBps,
4078
- void 0,
4155
+ quoteToAForSwap,
4079
4156
  {
4080
4157
  jupiterApiUrl: this.jupiterApiUrl,
4081
4158
  jupiterApiKey: this.jupiterApiKey
@@ -4088,7 +4165,7 @@ var Zap = class {
4088
4165
  swapAmountToB,
4089
4166
  maxAccounts,
4090
4167
  slippageBps,
4091
- void 0,
4168
+ quoteToBForSwap,
4092
4169
  {
4093
4170
  jupiterApiUrl: this.jupiterApiUrl,
4094
4171
  jupiterApiKey: this.jupiterApiKey
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meteora-ag/zap-sdk",
3
- "version": "1.2.0-rc.4",
3
+ "version": "1.2.0-rc.6",
4
4
  "description": "A Typescript SDK for interacting with the Zap program on Meteora.",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",