@meteora-ag/zap-sdk 1.0.0 → 1.0.2

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
@@ -116,34 +116,36 @@ type ZapOutParams = {
116
116
  type ZapOutThroughDammV2Params = {
117
117
  user: PublicKey;
118
118
  poolAddress: PublicKey;
119
- inputTokenAccount: PublicKey;
120
- outputTokenAccount: PublicKey;
119
+ inputMint: PublicKey;
120
+ outputMint: PublicKey;
121
+ inputTokenProgram: PublicKey;
122
+ outputTokenProgram: PublicKey;
121
123
  amountIn: BN;
122
124
  minimumSwapAmountOut: BN;
123
125
  maxSwapAmount: BN;
124
126
  percentageToZapOut: number;
125
- preInstructions?: TransactionInstruction[];
126
- postInstructions?: TransactionInstruction[];
127
127
  };
128
128
  type ZapOutThroughDlmmParams = {
129
129
  user: PublicKey;
130
130
  lbPairAddress: PublicKey;
131
- inputTokenAccount: PublicKey;
132
- outputTokenAccount: PublicKey;
131
+ inputMint: PublicKey;
132
+ outputMint: PublicKey;
133
+ inputTokenProgram: PublicKey;
134
+ outputTokenProgram: PublicKey;
133
135
  amountIn: BN;
134
136
  minimumSwapAmountOut: BN;
135
137
  maxSwapAmount: BN;
136
138
  percentageToZapOut: number;
137
- preInstructions?: TransactionInstruction[];
138
- postInstructions?: TransactionInstruction[];
139
139
  };
140
140
  interface ZapOutThroughJupiterParams {
141
- inputTokenAccount: PublicKey;
141
+ user: PublicKey;
142
+ inputMint: PublicKey;
143
+ outputMint: PublicKey;
144
+ inputTokenProgram: PublicKey;
145
+ outputTokenProgram: PublicKey;
142
146
  jupiterSwapResponse: JupiterSwapInstructionResponse;
143
147
  maxSwapAmount: BN;
144
148
  percentageToZapOut: number;
145
- preInstructions?: TransactionInstruction[];
146
- postInstructions?: TransactionInstruction[];
147
149
  }
148
150
  interface JupiterQuoteResponse {
149
151
  inputMint: string;
package/dist/index.d.ts CHANGED
@@ -116,34 +116,36 @@ type ZapOutParams = {
116
116
  type ZapOutThroughDammV2Params = {
117
117
  user: PublicKey;
118
118
  poolAddress: PublicKey;
119
- inputTokenAccount: PublicKey;
120
- outputTokenAccount: PublicKey;
119
+ inputMint: PublicKey;
120
+ outputMint: PublicKey;
121
+ inputTokenProgram: PublicKey;
122
+ outputTokenProgram: PublicKey;
121
123
  amountIn: BN;
122
124
  minimumSwapAmountOut: BN;
123
125
  maxSwapAmount: BN;
124
126
  percentageToZapOut: number;
125
- preInstructions?: TransactionInstruction[];
126
- postInstructions?: TransactionInstruction[];
127
127
  };
128
128
  type ZapOutThroughDlmmParams = {
129
129
  user: PublicKey;
130
130
  lbPairAddress: PublicKey;
131
- inputTokenAccount: PublicKey;
132
- outputTokenAccount: PublicKey;
131
+ inputMint: PublicKey;
132
+ outputMint: PublicKey;
133
+ inputTokenProgram: PublicKey;
134
+ outputTokenProgram: PublicKey;
133
135
  amountIn: BN;
134
136
  minimumSwapAmountOut: BN;
135
137
  maxSwapAmount: BN;
136
138
  percentageToZapOut: number;
137
- preInstructions?: TransactionInstruction[];
138
- postInstructions?: TransactionInstruction[];
139
139
  };
140
140
  interface ZapOutThroughJupiterParams {
141
- inputTokenAccount: PublicKey;
141
+ user: PublicKey;
142
+ inputMint: PublicKey;
143
+ outputMint: PublicKey;
144
+ inputTokenProgram: PublicKey;
145
+ outputTokenProgram: PublicKey;
142
146
  jupiterSwapResponse: JupiterSwapInstructionResponse;
143
147
  maxSwapAmount: BN;
144
148
  percentageToZapOut: number;
145
- preInstructions?: TransactionInstruction[];
146
- postInstructions?: TransactionInstruction[];
147
149
  }
148
150
  interface JupiterQuoteResponse {
149
151
  inputMint: string;
package/dist/index.js CHANGED
@@ -809,6 +809,7 @@ function createDlmmSwapPayload(amountIn, minimumSwapAmountOut, remainingAccounts
809
809
 
810
810
  // src/zap.ts
811
811
  var import_cp_amm_sdk2 = require("@meteora-ag/cp-amm-sdk");
812
+ var import_spl_token5 = require("@solana/spl-token");
812
813
  var Zap = class {
813
814
  constructor(connection) {
814
815
  this.connection = connection;
@@ -861,13 +862,40 @@ var Zap = class {
861
862
  zapOutThroughJupiter(params) {
862
863
  return __async(this, null, function* () {
863
864
  const {
864
- inputTokenAccount,
865
+ user,
866
+ inputMint,
867
+ outputMint,
868
+ inputTokenProgram,
869
+ outputTokenProgram,
865
870
  jupiterSwapResponse,
866
871
  maxSwapAmount,
867
- percentageToZapOut,
868
- preInstructions,
869
- postInstructions
872
+ percentageToZapOut
870
873
  } = params;
874
+ const preInstructions = [];
875
+ const postInstructions = [];
876
+ const [
877
+ { ataPubkey: inputTokenAccount, ix: inputTokenAccountIx },
878
+ { ataPubkey: outputTokenAccount, ix: outputTokenAccountIx }
879
+ ] = yield Promise.all([
880
+ getOrCreateATAInstruction(
881
+ this.connection,
882
+ inputMint,
883
+ user,
884
+ user,
885
+ true,
886
+ inputTokenProgram
887
+ ),
888
+ getOrCreateATAInstruction(
889
+ this.connection,
890
+ outputMint,
891
+ user,
892
+ user,
893
+ true,
894
+ outputTokenProgram
895
+ )
896
+ ]);
897
+ inputTokenAccountIx && preInstructions.push(inputTokenAccountIx);
898
+ outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
871
899
  const preUserTokenBalance = (yield this.connection.getTokenAccountBalance(inputTokenAccount)).value.amount;
872
900
  const remainingAccounts = jupiterSwapResponse.swapInstruction.accounts.map(
873
901
  (account) => {
@@ -884,6 +912,12 @@ var Zap = class {
884
912
  "base64"
885
913
  );
886
914
  const offsetAmountIn = payloadData.length - AMOUNT_IN_JUP_V6_REVERSE_OFFSET;
915
+ if (outputMint.equals(import_spl_token5.NATIVE_MINT)) {
916
+ const unwrapInstructions = unwrapSOLInstruction(user, user);
917
+ if (unwrapInstructions) {
918
+ postInstructions.push(unwrapInstructions);
919
+ }
920
+ }
887
921
  return yield this.zapOut({
888
922
  userTokenInAccount: inputTokenAccount,
889
923
  zapOutParams: {
@@ -895,8 +929,8 @@ var Zap = class {
895
929
  },
896
930
  remainingAccounts,
897
931
  ammProgram: JUP_V6_PROGRAM_ID,
898
- preInstructions: preInstructions || [],
899
- postInstructions: postInstructions || []
932
+ preInstructions,
933
+ postInstructions
900
934
  });
901
935
  });
902
936
  }
@@ -919,16 +953,41 @@ var Zap = class {
919
953
  const {
920
954
  user,
921
955
  poolAddress,
922
- inputTokenAccount,
923
- outputTokenAccount,
956
+ inputMint,
957
+ outputMint,
958
+ inputTokenProgram,
959
+ outputTokenProgram,
924
960
  amountIn,
925
961
  minimumSwapAmountOut,
926
962
  maxSwapAmount,
927
- percentageToZapOut,
928
- preInstructions,
929
- postInstructions
963
+ percentageToZapOut
930
964
  } = params;
931
965
  const poolState = yield getDammV2Pool(this.connection, poolAddress);
966
+ const preInstructions = [];
967
+ const postInstructions = [];
968
+ const [
969
+ { ataPubkey: inputTokenAccount, ix: inputTokenAccountIx },
970
+ { ataPubkey: outputTokenAccount, ix: outputTokenAccountIx }
971
+ ] = yield Promise.all([
972
+ getOrCreateATAInstruction(
973
+ this.connection,
974
+ inputMint,
975
+ user,
976
+ user,
977
+ true,
978
+ inputTokenProgram
979
+ ),
980
+ getOrCreateATAInstruction(
981
+ this.connection,
982
+ outputMint,
983
+ user,
984
+ user,
985
+ true,
986
+ outputTokenProgram
987
+ )
988
+ ]);
989
+ inputTokenAccountIx && preInstructions.push(inputTokenAccountIx);
990
+ outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
932
991
  const preUserTokenBalance = (yield this.connection.getTokenAccountBalance(inputTokenAccount)).value.amount;
933
992
  const remainingAccounts = yield getDammV2RemainingAccounts(
934
993
  poolAddress,
@@ -941,6 +1000,12 @@ var Zap = class {
941
1000
  );
942
1001
  const payloadData = createDammV2SwapPayload(amountIn, minimumSwapAmountOut);
943
1002
  const offsetAmountIn = AMOUNT_IN_DAMM_V2_OFFSET;
1003
+ if (outputMint.equals(import_spl_token5.NATIVE_MINT)) {
1004
+ const unwrapInstructions = unwrapSOLInstruction(user, user);
1005
+ if (unwrapInstructions) {
1006
+ postInstructions.push(unwrapInstructions);
1007
+ }
1008
+ }
944
1009
  return yield this.zapOut({
945
1010
  userTokenInAccount: inputTokenAccount,
946
1011
  zapOutParams: {
@@ -952,8 +1017,8 @@ var Zap = class {
952
1017
  },
953
1018
  remainingAccounts,
954
1019
  ammProgram: DAMM_V2_PROGRAM_ID,
955
- preInstructions: preInstructions || [],
956
- postInstructions: postInstructions || []
1020
+ preInstructions,
1021
+ postInstructions
957
1022
  });
958
1023
  });
959
1024
  }
@@ -976,16 +1041,41 @@ var Zap = class {
976
1041
  const {
977
1042
  user,
978
1043
  lbPairAddress,
979
- inputTokenAccount,
980
- outputTokenAccount,
1044
+ inputMint,
1045
+ outputMint,
1046
+ inputTokenProgram,
1047
+ outputTokenProgram,
981
1048
  amountIn,
982
1049
  minimumSwapAmountOut,
983
1050
  maxSwapAmount,
984
- percentageToZapOut,
985
- preInstructions,
986
- postInstructions
1051
+ percentageToZapOut
987
1052
  } = params;
988
1053
  const lbPairState = yield getLbPairState(this.connection, lbPairAddress);
1054
+ const preInstructions = [];
1055
+ const postInstructions = [];
1056
+ const [
1057
+ { ataPubkey: inputTokenAccount, ix: inputTokenAccountIx },
1058
+ { ataPubkey: outputTokenAccount, ix: outputTokenAccountIx }
1059
+ ] = yield Promise.all([
1060
+ getOrCreateATAInstruction(
1061
+ this.connection,
1062
+ inputMint,
1063
+ user,
1064
+ user,
1065
+ true,
1066
+ inputTokenProgram
1067
+ ),
1068
+ getOrCreateATAInstruction(
1069
+ this.connection,
1070
+ outputMint,
1071
+ user,
1072
+ user,
1073
+ true,
1074
+ outputTokenProgram
1075
+ )
1076
+ ]);
1077
+ inputTokenAccountIx && preInstructions.push(inputTokenAccountIx);
1078
+ outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
989
1079
  const preUserTokenBalance = (yield this.connection.getTokenAccountBalance(inputTokenAccount)).value.amount;
990
1080
  const { remainingAccounts, remainingAccountsInfo } = yield getDlmmRemainingAccounts(
991
1081
  this.connection,
@@ -1002,6 +1092,12 @@ var Zap = class {
1002
1092
  minimumSwapAmountOut,
1003
1093
  remainingAccountsInfo
1004
1094
  );
1095
+ if (outputMint.equals(import_spl_token5.NATIVE_MINT)) {
1096
+ const unwrapInstructions = unwrapSOLInstruction(user, user);
1097
+ if (unwrapInstructions) {
1098
+ postInstructions.push(unwrapInstructions);
1099
+ }
1100
+ }
1005
1101
  return yield this.zapOut({
1006
1102
  userTokenInAccount: inputTokenAccount,
1007
1103
  zapOutParams: {
@@ -1013,8 +1109,8 @@ var Zap = class {
1013
1109
  },
1014
1110
  remainingAccounts,
1015
1111
  ammProgram: DLMM_PROGRAM_ID,
1016
- preInstructions: preInstructions || [],
1017
- postInstructions: postInstructions || []
1112
+ preInstructions,
1113
+ postInstructions
1018
1114
  });
1019
1115
  });
1020
1116
  }
package/dist/index.mjs CHANGED
@@ -39,7 +39,9 @@ var __async = (__this, __arguments, generator) => {
39
39
  };
40
40
 
41
41
  // src/zap.ts
42
- import { PublicKey as PublicKey7 } from "@solana/web3.js";
42
+ import {
43
+ PublicKey as PublicKey7
44
+ } from "@solana/web3.js";
43
45
  import { BN as BN3, Program } from "@coral-xyz/anchor";
44
46
 
45
47
  // src/idl/zap/idl.json
@@ -777,6 +779,7 @@ function createDlmmSwapPayload(amountIn, minimumSwapAmountOut, remainingAccounts
777
779
 
778
780
  // src/zap.ts
779
781
  import { getTokenProgram } from "@meteora-ag/cp-amm-sdk";
782
+ import { NATIVE_MINT as NATIVE_MINT3 } from "@solana/spl-token";
780
783
  var Zap = class {
781
784
  constructor(connection) {
782
785
  this.connection = connection;
@@ -829,13 +832,40 @@ var Zap = class {
829
832
  zapOutThroughJupiter(params) {
830
833
  return __async(this, null, function* () {
831
834
  const {
832
- inputTokenAccount,
835
+ user,
836
+ inputMint,
837
+ outputMint,
838
+ inputTokenProgram,
839
+ outputTokenProgram,
833
840
  jupiterSwapResponse,
834
841
  maxSwapAmount,
835
- percentageToZapOut,
836
- preInstructions,
837
- postInstructions
842
+ percentageToZapOut
838
843
  } = params;
844
+ const preInstructions = [];
845
+ const postInstructions = [];
846
+ const [
847
+ { ataPubkey: inputTokenAccount, ix: inputTokenAccountIx },
848
+ { ataPubkey: outputTokenAccount, ix: outputTokenAccountIx }
849
+ ] = yield Promise.all([
850
+ getOrCreateATAInstruction(
851
+ this.connection,
852
+ inputMint,
853
+ user,
854
+ user,
855
+ true,
856
+ inputTokenProgram
857
+ ),
858
+ getOrCreateATAInstruction(
859
+ this.connection,
860
+ outputMint,
861
+ user,
862
+ user,
863
+ true,
864
+ outputTokenProgram
865
+ )
866
+ ]);
867
+ inputTokenAccountIx && preInstructions.push(inputTokenAccountIx);
868
+ outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
839
869
  const preUserTokenBalance = (yield this.connection.getTokenAccountBalance(inputTokenAccount)).value.amount;
840
870
  const remainingAccounts = jupiterSwapResponse.swapInstruction.accounts.map(
841
871
  (account) => {
@@ -852,6 +882,12 @@ var Zap = class {
852
882
  "base64"
853
883
  );
854
884
  const offsetAmountIn = payloadData.length - AMOUNT_IN_JUP_V6_REVERSE_OFFSET;
885
+ if (outputMint.equals(NATIVE_MINT3)) {
886
+ const unwrapInstructions = unwrapSOLInstruction(user, user);
887
+ if (unwrapInstructions) {
888
+ postInstructions.push(unwrapInstructions);
889
+ }
890
+ }
855
891
  return yield this.zapOut({
856
892
  userTokenInAccount: inputTokenAccount,
857
893
  zapOutParams: {
@@ -863,8 +899,8 @@ var Zap = class {
863
899
  },
864
900
  remainingAccounts,
865
901
  ammProgram: JUP_V6_PROGRAM_ID,
866
- preInstructions: preInstructions || [],
867
- postInstructions: postInstructions || []
902
+ preInstructions,
903
+ postInstructions
868
904
  });
869
905
  });
870
906
  }
@@ -887,16 +923,41 @@ var Zap = class {
887
923
  const {
888
924
  user,
889
925
  poolAddress,
890
- inputTokenAccount,
891
- outputTokenAccount,
926
+ inputMint,
927
+ outputMint,
928
+ inputTokenProgram,
929
+ outputTokenProgram,
892
930
  amountIn,
893
931
  minimumSwapAmountOut,
894
932
  maxSwapAmount,
895
- percentageToZapOut,
896
- preInstructions,
897
- postInstructions
933
+ percentageToZapOut
898
934
  } = params;
899
935
  const poolState = yield getDammV2Pool(this.connection, poolAddress);
936
+ const preInstructions = [];
937
+ const postInstructions = [];
938
+ const [
939
+ { ataPubkey: inputTokenAccount, ix: inputTokenAccountIx },
940
+ { ataPubkey: outputTokenAccount, ix: outputTokenAccountIx }
941
+ ] = yield Promise.all([
942
+ getOrCreateATAInstruction(
943
+ this.connection,
944
+ inputMint,
945
+ user,
946
+ user,
947
+ true,
948
+ inputTokenProgram
949
+ ),
950
+ getOrCreateATAInstruction(
951
+ this.connection,
952
+ outputMint,
953
+ user,
954
+ user,
955
+ true,
956
+ outputTokenProgram
957
+ )
958
+ ]);
959
+ inputTokenAccountIx && preInstructions.push(inputTokenAccountIx);
960
+ outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
900
961
  const preUserTokenBalance = (yield this.connection.getTokenAccountBalance(inputTokenAccount)).value.amount;
901
962
  const remainingAccounts = yield getDammV2RemainingAccounts(
902
963
  poolAddress,
@@ -909,6 +970,12 @@ var Zap = class {
909
970
  );
910
971
  const payloadData = createDammV2SwapPayload(amountIn, minimumSwapAmountOut);
911
972
  const offsetAmountIn = AMOUNT_IN_DAMM_V2_OFFSET;
973
+ if (outputMint.equals(NATIVE_MINT3)) {
974
+ const unwrapInstructions = unwrapSOLInstruction(user, user);
975
+ if (unwrapInstructions) {
976
+ postInstructions.push(unwrapInstructions);
977
+ }
978
+ }
912
979
  return yield this.zapOut({
913
980
  userTokenInAccount: inputTokenAccount,
914
981
  zapOutParams: {
@@ -920,8 +987,8 @@ var Zap = class {
920
987
  },
921
988
  remainingAccounts,
922
989
  ammProgram: DAMM_V2_PROGRAM_ID,
923
- preInstructions: preInstructions || [],
924
- postInstructions: postInstructions || []
990
+ preInstructions,
991
+ postInstructions
925
992
  });
926
993
  });
927
994
  }
@@ -944,16 +1011,41 @@ var Zap = class {
944
1011
  const {
945
1012
  user,
946
1013
  lbPairAddress,
947
- inputTokenAccount,
948
- outputTokenAccount,
1014
+ inputMint,
1015
+ outputMint,
1016
+ inputTokenProgram,
1017
+ outputTokenProgram,
949
1018
  amountIn,
950
1019
  minimumSwapAmountOut,
951
1020
  maxSwapAmount,
952
- percentageToZapOut,
953
- preInstructions,
954
- postInstructions
1021
+ percentageToZapOut
955
1022
  } = params;
956
1023
  const lbPairState = yield getLbPairState(this.connection, lbPairAddress);
1024
+ const preInstructions = [];
1025
+ const postInstructions = [];
1026
+ const [
1027
+ { ataPubkey: inputTokenAccount, ix: inputTokenAccountIx },
1028
+ { ataPubkey: outputTokenAccount, ix: outputTokenAccountIx }
1029
+ ] = yield Promise.all([
1030
+ getOrCreateATAInstruction(
1031
+ this.connection,
1032
+ inputMint,
1033
+ user,
1034
+ user,
1035
+ true,
1036
+ inputTokenProgram
1037
+ ),
1038
+ getOrCreateATAInstruction(
1039
+ this.connection,
1040
+ outputMint,
1041
+ user,
1042
+ user,
1043
+ true,
1044
+ outputTokenProgram
1045
+ )
1046
+ ]);
1047
+ inputTokenAccountIx && preInstructions.push(inputTokenAccountIx);
1048
+ outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
957
1049
  const preUserTokenBalance = (yield this.connection.getTokenAccountBalance(inputTokenAccount)).value.amount;
958
1050
  const { remainingAccounts, remainingAccountsInfo } = yield getDlmmRemainingAccounts(
959
1051
  this.connection,
@@ -970,6 +1062,12 @@ var Zap = class {
970
1062
  minimumSwapAmountOut,
971
1063
  remainingAccountsInfo
972
1064
  );
1065
+ if (outputMint.equals(NATIVE_MINT3)) {
1066
+ const unwrapInstructions = unwrapSOLInstruction(user, user);
1067
+ if (unwrapInstructions) {
1068
+ postInstructions.push(unwrapInstructions);
1069
+ }
1070
+ }
973
1071
  return yield this.zapOut({
974
1072
  userTokenInAccount: inputTokenAccount,
975
1073
  zapOutParams: {
@@ -981,8 +1079,8 @@ var Zap = class {
981
1079
  },
982
1080
  remainingAccounts,
983
1081
  ammProgram: DLMM_PROGRAM_ID,
984
- preInstructions: preInstructions || [],
985
- postInstructions: postInstructions || []
1082
+ preInstructions,
1083
+ postInstructions
986
1084
  });
987
1085
  });
988
1086
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meteora-ag/zap-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
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",