@meteora-ag/zap-sdk 1.0.0 → 1.0.1

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,30 @@ 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
121
  amountIn: BN;
122
122
  minimumSwapAmountOut: BN;
123
123
  maxSwapAmount: BN;
124
124
  percentageToZapOut: number;
125
- preInstructions?: TransactionInstruction[];
126
- postInstructions?: TransactionInstruction[];
127
125
  };
128
126
  type ZapOutThroughDlmmParams = {
129
127
  user: PublicKey;
130
128
  lbPairAddress: PublicKey;
131
- inputTokenAccount: PublicKey;
132
- outputTokenAccount: PublicKey;
129
+ inputMint: PublicKey;
130
+ outputMint: PublicKey;
133
131
  amountIn: BN;
134
132
  minimumSwapAmountOut: BN;
135
133
  maxSwapAmount: BN;
136
134
  percentageToZapOut: number;
137
- preInstructions?: TransactionInstruction[];
138
- postInstructions?: TransactionInstruction[];
139
135
  };
140
136
  interface ZapOutThroughJupiterParams {
141
- inputTokenAccount: PublicKey;
137
+ user: PublicKey;
138
+ inputMint: PublicKey;
139
+ outputMint: PublicKey;
142
140
  jupiterSwapResponse: JupiterSwapInstructionResponse;
143
141
  maxSwapAmount: BN;
144
142
  percentageToZapOut: number;
145
- preInstructions?: TransactionInstruction[];
146
- postInstructions?: TransactionInstruction[];
147
143
  }
148
144
  interface JupiterQuoteResponse {
149
145
  inputMint: string;
package/dist/index.d.ts CHANGED
@@ -116,34 +116,30 @@ 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
121
  amountIn: BN;
122
122
  minimumSwapAmountOut: BN;
123
123
  maxSwapAmount: BN;
124
124
  percentageToZapOut: number;
125
- preInstructions?: TransactionInstruction[];
126
- postInstructions?: TransactionInstruction[];
127
125
  };
128
126
  type ZapOutThroughDlmmParams = {
129
127
  user: PublicKey;
130
128
  lbPairAddress: PublicKey;
131
- inputTokenAccount: PublicKey;
132
- outputTokenAccount: PublicKey;
129
+ inputMint: PublicKey;
130
+ outputMint: PublicKey;
133
131
  amountIn: BN;
134
132
  minimumSwapAmountOut: BN;
135
133
  maxSwapAmount: BN;
136
134
  percentageToZapOut: number;
137
- preInstructions?: TransactionInstruction[];
138
- postInstructions?: TransactionInstruction[];
139
135
  };
140
136
  interface ZapOutThroughJupiterParams {
141
- inputTokenAccount: PublicKey;
137
+ user: PublicKey;
138
+ inputMint: PublicKey;
139
+ outputMint: PublicKey;
142
140
  jupiterSwapResponse: JupiterSwapInstructionResponse;
143
141
  maxSwapAmount: BN;
144
142
  percentageToZapOut: number;
145
- preInstructions?: TransactionInstruction[];
146
- postInstructions?: TransactionInstruction[];
147
143
  }
148
144
  interface JupiterQuoteResponse {
149
145
  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,42 @@ 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,
865
868
  jupiterSwapResponse,
866
869
  maxSwapAmount,
867
- percentageToZapOut,
868
- preInstructions,
869
- postInstructions
870
+ percentageToZapOut
870
871
  } = params;
872
+ const preInstructions = [];
873
+ const postInstructions = [];
874
+ const [inputTokenProgram, outputTokenProgram] = yield Promise.all([
875
+ getTokenProgramFromMint(this.connection, inputMint),
876
+ getTokenProgramFromMint(this.connection, outputMint)
877
+ ]);
878
+ const [
879
+ { ataPubkey: inputTokenAccount, ix: inputTokenAccountIx },
880
+ { ataPubkey: outputTokenAccount, ix: outputTokenAccountIx }
881
+ ] = yield Promise.all([
882
+ getOrCreateATAInstruction(
883
+ this.connection,
884
+ inputMint,
885
+ user,
886
+ user,
887
+ true,
888
+ inputTokenProgram
889
+ ),
890
+ getOrCreateATAInstruction(
891
+ this.connection,
892
+ outputMint,
893
+ user,
894
+ user,
895
+ true,
896
+ outputTokenProgram
897
+ )
898
+ ]);
899
+ inputTokenAccountIx && preInstructions.push(inputTokenAccountIx);
900
+ outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
871
901
  const preUserTokenBalance = (yield this.connection.getTokenAccountBalance(inputTokenAccount)).value.amount;
872
902
  const remainingAccounts = jupiterSwapResponse.swapInstruction.accounts.map(
873
903
  (account) => {
@@ -884,6 +914,12 @@ var Zap = class {
884
914
  "base64"
885
915
  );
886
916
  const offsetAmountIn = payloadData.length - AMOUNT_IN_JUP_V6_REVERSE_OFFSET;
917
+ if (outputMint.equals(import_spl_token5.NATIVE_MINT)) {
918
+ const unwrapInstructions = unwrapSOLInstruction(user, user);
919
+ if (unwrapInstructions) {
920
+ postInstructions.push(unwrapInstructions);
921
+ }
922
+ }
887
923
  return yield this.zapOut({
888
924
  userTokenInAccount: inputTokenAccount,
889
925
  zapOutParams: {
@@ -895,8 +931,8 @@ var Zap = class {
895
931
  },
896
932
  remainingAccounts,
897
933
  ammProgram: JUP_V6_PROGRAM_ID,
898
- preInstructions: preInstructions || [],
899
- postInstructions: postInstructions || []
934
+ preInstructions,
935
+ postInstructions
900
936
  });
901
937
  });
902
938
  }
@@ -919,16 +955,43 @@ var Zap = class {
919
955
  const {
920
956
  user,
921
957
  poolAddress,
922
- inputTokenAccount,
923
- outputTokenAccount,
958
+ inputMint,
959
+ outputMint,
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 [inputTokenProgram, outputTokenProgram] = yield Promise.all([
969
+ getTokenProgramFromMint(this.connection, inputMint),
970
+ getTokenProgramFromMint(this.connection, outputMint)
971
+ ]);
972
+ const [
973
+ { ataPubkey: inputTokenAccount, ix: inputTokenAccountIx },
974
+ { ataPubkey: outputTokenAccount, ix: outputTokenAccountIx }
975
+ ] = yield Promise.all([
976
+ getOrCreateATAInstruction(
977
+ this.connection,
978
+ inputMint,
979
+ user,
980
+ user,
981
+ true,
982
+ inputTokenProgram
983
+ ),
984
+ getOrCreateATAInstruction(
985
+ this.connection,
986
+ outputMint,
987
+ user,
988
+ user,
989
+ true,
990
+ outputTokenProgram
991
+ )
992
+ ]);
993
+ inputTokenAccountIx && preInstructions.push(inputTokenAccountIx);
994
+ outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
932
995
  const preUserTokenBalance = (yield this.connection.getTokenAccountBalance(inputTokenAccount)).value.amount;
933
996
  const remainingAccounts = yield getDammV2RemainingAccounts(
934
997
  poolAddress,
@@ -941,6 +1004,12 @@ var Zap = class {
941
1004
  );
942
1005
  const payloadData = createDammV2SwapPayload(amountIn, minimumSwapAmountOut);
943
1006
  const offsetAmountIn = AMOUNT_IN_DAMM_V2_OFFSET;
1007
+ if (outputMint.equals(import_spl_token5.NATIVE_MINT)) {
1008
+ const unwrapInstructions = unwrapSOLInstruction(user, user);
1009
+ if (unwrapInstructions) {
1010
+ postInstructions.push(unwrapInstructions);
1011
+ }
1012
+ }
944
1013
  return yield this.zapOut({
945
1014
  userTokenInAccount: inputTokenAccount,
946
1015
  zapOutParams: {
@@ -952,8 +1021,8 @@ var Zap = class {
952
1021
  },
953
1022
  remainingAccounts,
954
1023
  ammProgram: DAMM_V2_PROGRAM_ID,
955
- preInstructions: preInstructions || [],
956
- postInstructions: postInstructions || []
1024
+ preInstructions,
1025
+ postInstructions
957
1026
  });
958
1027
  });
959
1028
  }
@@ -976,16 +1045,43 @@ var Zap = class {
976
1045
  const {
977
1046
  user,
978
1047
  lbPairAddress,
979
- inputTokenAccount,
980
- outputTokenAccount,
1048
+ inputMint,
1049
+ outputMint,
981
1050
  amountIn,
982
1051
  minimumSwapAmountOut,
983
1052
  maxSwapAmount,
984
- percentageToZapOut,
985
- preInstructions,
986
- postInstructions
1053
+ percentageToZapOut
987
1054
  } = params;
988
1055
  const lbPairState = yield getLbPairState(this.connection, lbPairAddress);
1056
+ const preInstructions = [];
1057
+ const postInstructions = [];
1058
+ const [inputTokenProgram, outputTokenProgram] = yield Promise.all([
1059
+ getTokenProgramFromMint(this.connection, inputMint),
1060
+ getTokenProgramFromMint(this.connection, outputMint)
1061
+ ]);
1062
+ const [
1063
+ { ataPubkey: inputTokenAccount, ix: inputTokenAccountIx },
1064
+ { ataPubkey: outputTokenAccount, ix: outputTokenAccountIx }
1065
+ ] = yield Promise.all([
1066
+ getOrCreateATAInstruction(
1067
+ this.connection,
1068
+ inputMint,
1069
+ user,
1070
+ user,
1071
+ true,
1072
+ inputTokenProgram
1073
+ ),
1074
+ getOrCreateATAInstruction(
1075
+ this.connection,
1076
+ outputMint,
1077
+ user,
1078
+ user,
1079
+ true,
1080
+ outputTokenProgram
1081
+ )
1082
+ ]);
1083
+ inputTokenAccountIx && preInstructions.push(inputTokenAccountIx);
1084
+ outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
989
1085
  const preUserTokenBalance = (yield this.connection.getTokenAccountBalance(inputTokenAccount)).value.amount;
990
1086
  const { remainingAccounts, remainingAccountsInfo } = yield getDlmmRemainingAccounts(
991
1087
  this.connection,
@@ -1002,6 +1098,12 @@ var Zap = class {
1002
1098
  minimumSwapAmountOut,
1003
1099
  remainingAccountsInfo
1004
1100
  );
1101
+ if (outputMint.equals(import_spl_token5.NATIVE_MINT)) {
1102
+ const unwrapInstructions = unwrapSOLInstruction(user, user);
1103
+ if (unwrapInstructions) {
1104
+ postInstructions.push(unwrapInstructions);
1105
+ }
1106
+ }
1005
1107
  return yield this.zapOut({
1006
1108
  userTokenInAccount: inputTokenAccount,
1007
1109
  zapOutParams: {
@@ -1013,8 +1115,8 @@ var Zap = class {
1013
1115
  },
1014
1116
  remainingAccounts,
1015
1117
  ammProgram: DLMM_PROGRAM_ID,
1016
- preInstructions: preInstructions || [],
1017
- postInstructions: postInstructions || []
1118
+ preInstructions,
1119
+ postInstructions
1018
1120
  });
1019
1121
  });
1020
1122
  }
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,42 @@ 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,
833
838
  jupiterSwapResponse,
834
839
  maxSwapAmount,
835
- percentageToZapOut,
836
- preInstructions,
837
- postInstructions
840
+ percentageToZapOut
838
841
  } = params;
842
+ const preInstructions = [];
843
+ const postInstructions = [];
844
+ const [inputTokenProgram, outputTokenProgram] = yield Promise.all([
845
+ getTokenProgramFromMint(this.connection, inputMint),
846
+ getTokenProgramFromMint(this.connection, outputMint)
847
+ ]);
848
+ const [
849
+ { ataPubkey: inputTokenAccount, ix: inputTokenAccountIx },
850
+ { ataPubkey: outputTokenAccount, ix: outputTokenAccountIx }
851
+ ] = yield Promise.all([
852
+ getOrCreateATAInstruction(
853
+ this.connection,
854
+ inputMint,
855
+ user,
856
+ user,
857
+ true,
858
+ inputTokenProgram
859
+ ),
860
+ getOrCreateATAInstruction(
861
+ this.connection,
862
+ outputMint,
863
+ user,
864
+ user,
865
+ true,
866
+ outputTokenProgram
867
+ )
868
+ ]);
869
+ inputTokenAccountIx && preInstructions.push(inputTokenAccountIx);
870
+ outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
839
871
  const preUserTokenBalance = (yield this.connection.getTokenAccountBalance(inputTokenAccount)).value.amount;
840
872
  const remainingAccounts = jupiterSwapResponse.swapInstruction.accounts.map(
841
873
  (account) => {
@@ -852,6 +884,12 @@ var Zap = class {
852
884
  "base64"
853
885
  );
854
886
  const offsetAmountIn = payloadData.length - AMOUNT_IN_JUP_V6_REVERSE_OFFSET;
887
+ if (outputMint.equals(NATIVE_MINT3)) {
888
+ const unwrapInstructions = unwrapSOLInstruction(user, user);
889
+ if (unwrapInstructions) {
890
+ postInstructions.push(unwrapInstructions);
891
+ }
892
+ }
855
893
  return yield this.zapOut({
856
894
  userTokenInAccount: inputTokenAccount,
857
895
  zapOutParams: {
@@ -863,8 +901,8 @@ var Zap = class {
863
901
  },
864
902
  remainingAccounts,
865
903
  ammProgram: JUP_V6_PROGRAM_ID,
866
- preInstructions: preInstructions || [],
867
- postInstructions: postInstructions || []
904
+ preInstructions,
905
+ postInstructions
868
906
  });
869
907
  });
870
908
  }
@@ -887,16 +925,43 @@ var Zap = class {
887
925
  const {
888
926
  user,
889
927
  poolAddress,
890
- inputTokenAccount,
891
- outputTokenAccount,
928
+ inputMint,
929
+ outputMint,
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 [inputTokenProgram, outputTokenProgram] = yield Promise.all([
939
+ getTokenProgramFromMint(this.connection, inputMint),
940
+ getTokenProgramFromMint(this.connection, outputMint)
941
+ ]);
942
+ const [
943
+ { ataPubkey: inputTokenAccount, ix: inputTokenAccountIx },
944
+ { ataPubkey: outputTokenAccount, ix: outputTokenAccountIx }
945
+ ] = yield Promise.all([
946
+ getOrCreateATAInstruction(
947
+ this.connection,
948
+ inputMint,
949
+ user,
950
+ user,
951
+ true,
952
+ inputTokenProgram
953
+ ),
954
+ getOrCreateATAInstruction(
955
+ this.connection,
956
+ outputMint,
957
+ user,
958
+ user,
959
+ true,
960
+ outputTokenProgram
961
+ )
962
+ ]);
963
+ inputTokenAccountIx && preInstructions.push(inputTokenAccountIx);
964
+ outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
900
965
  const preUserTokenBalance = (yield this.connection.getTokenAccountBalance(inputTokenAccount)).value.amount;
901
966
  const remainingAccounts = yield getDammV2RemainingAccounts(
902
967
  poolAddress,
@@ -909,6 +974,12 @@ var Zap = class {
909
974
  );
910
975
  const payloadData = createDammV2SwapPayload(amountIn, minimumSwapAmountOut);
911
976
  const offsetAmountIn = AMOUNT_IN_DAMM_V2_OFFSET;
977
+ if (outputMint.equals(NATIVE_MINT3)) {
978
+ const unwrapInstructions = unwrapSOLInstruction(user, user);
979
+ if (unwrapInstructions) {
980
+ postInstructions.push(unwrapInstructions);
981
+ }
982
+ }
912
983
  return yield this.zapOut({
913
984
  userTokenInAccount: inputTokenAccount,
914
985
  zapOutParams: {
@@ -920,8 +991,8 @@ var Zap = class {
920
991
  },
921
992
  remainingAccounts,
922
993
  ammProgram: DAMM_V2_PROGRAM_ID,
923
- preInstructions: preInstructions || [],
924
- postInstructions: postInstructions || []
994
+ preInstructions,
995
+ postInstructions
925
996
  });
926
997
  });
927
998
  }
@@ -944,16 +1015,43 @@ var Zap = class {
944
1015
  const {
945
1016
  user,
946
1017
  lbPairAddress,
947
- inputTokenAccount,
948
- outputTokenAccount,
1018
+ inputMint,
1019
+ outputMint,
949
1020
  amountIn,
950
1021
  minimumSwapAmountOut,
951
1022
  maxSwapAmount,
952
- percentageToZapOut,
953
- preInstructions,
954
- postInstructions
1023
+ percentageToZapOut
955
1024
  } = params;
956
1025
  const lbPairState = yield getLbPairState(this.connection, lbPairAddress);
1026
+ const preInstructions = [];
1027
+ const postInstructions = [];
1028
+ const [inputTokenProgram, outputTokenProgram] = yield Promise.all([
1029
+ getTokenProgramFromMint(this.connection, inputMint),
1030
+ getTokenProgramFromMint(this.connection, outputMint)
1031
+ ]);
1032
+ const [
1033
+ { ataPubkey: inputTokenAccount, ix: inputTokenAccountIx },
1034
+ { ataPubkey: outputTokenAccount, ix: outputTokenAccountIx }
1035
+ ] = yield Promise.all([
1036
+ getOrCreateATAInstruction(
1037
+ this.connection,
1038
+ inputMint,
1039
+ user,
1040
+ user,
1041
+ true,
1042
+ inputTokenProgram
1043
+ ),
1044
+ getOrCreateATAInstruction(
1045
+ this.connection,
1046
+ outputMint,
1047
+ user,
1048
+ user,
1049
+ true,
1050
+ outputTokenProgram
1051
+ )
1052
+ ]);
1053
+ inputTokenAccountIx && preInstructions.push(inputTokenAccountIx);
1054
+ outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
957
1055
  const preUserTokenBalance = (yield this.connection.getTokenAccountBalance(inputTokenAccount)).value.amount;
958
1056
  const { remainingAccounts, remainingAccountsInfo } = yield getDlmmRemainingAccounts(
959
1057
  this.connection,
@@ -970,6 +1068,12 @@ var Zap = class {
970
1068
  minimumSwapAmountOut,
971
1069
  remainingAccountsInfo
972
1070
  );
1071
+ if (outputMint.equals(NATIVE_MINT3)) {
1072
+ const unwrapInstructions = unwrapSOLInstruction(user, user);
1073
+ if (unwrapInstructions) {
1074
+ postInstructions.push(unwrapInstructions);
1075
+ }
1076
+ }
973
1077
  return yield this.zapOut({
974
1078
  userTokenInAccount: inputTokenAccount,
975
1079
  zapOutParams: {
@@ -981,8 +1085,8 @@ var Zap = class {
981
1085
  },
982
1086
  remainingAccounts,
983
1087
  ammProgram: DLMM_PROGRAM_ID,
984
- preInstructions: preInstructions || [],
985
- postInstructions: postInstructions || []
1088
+ preInstructions,
1089
+ postInstructions
986
1090
  });
987
1091
  });
988
1092
  }
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.1",
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",