@meteora-ag/zap-sdk 1.0.2 → 1.0.4
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 +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +40 -3
- package/dist/index.mjs +39 -3
- package/package.json +5 -4
package/dist/index.d.mts
CHANGED
|
@@ -320,6 +320,13 @@ declare const getOrCreateATAInstruction: (connection: Connection, tokenMint: Pub
|
|
|
320
320
|
* @returns The unwrap SOL instruction
|
|
321
321
|
*/
|
|
322
322
|
declare function unwrapSOLInstruction(owner: PublicKey, receiver: PublicKey, allowOwnerOffCurve?: boolean): TransactionInstruction | null;
|
|
323
|
+
/**
|
|
324
|
+
* Get token account balance
|
|
325
|
+
* @param connection - Solana connection
|
|
326
|
+
* @param tokenAccount - The token account address
|
|
327
|
+
* @returns The token account balance as a string
|
|
328
|
+
*/
|
|
329
|
+
declare function getTokenAccountBalance(connection: Connection, tokenAccount: PublicKey): Promise<string>;
|
|
323
330
|
/**
|
|
324
331
|
* Wrap SOL instruction
|
|
325
332
|
* @param from - The from address
|
|
@@ -380,4 +387,4 @@ declare const AMOUNT_IN_JUP_V6_REVERSE_OFFSET = 19;
|
|
|
380
387
|
declare const AMOUNT_IN_DAMM_V2_OFFSET = 8;
|
|
381
388
|
declare const DAMM_V2_SWAP_DISCRIMINATOR: number[];
|
|
382
389
|
|
|
383
|
-
export { AMOUNT_IN_DAMM_V2_OFFSET, AMOUNT_IN_DLMM_OFFSET, AMOUNT_IN_JUP_V6_REVERSE_OFFSET, AccountsType, BIN_ARRAY_INDEX_BOUND, DAMM_V2_PROGRAM_ID, DAMM_V2_SWAP_DISCRIMINATOR, DLMM_PROGRAM_ID, DLMM_SWAP_DISCRIMINATOR, JUP_V6_PROGRAM_ID, type JupiterInstruction, type JupiterQuoteResponse, type JupiterRoutePlan, type JupiterSwapInstructionResponse, MEMO_PROGRAM_ID, ZAP_PROGRAM_ID, Zap, type ZapOutParameters, type ZapOutParams, type ZapOutThroughDammV2Params, type ZapOutThroughDlmmParams, type ZapOutThroughJupiterParams, type ZapProgram, convertAccountTypeToNumber, createDammV2SwapPayload, createDlmmSwapPayload, deriveDammV2EventAuthority, getBinArrayBitmapExtension, getBitFromBinArrayIndexInBitmapExtension, getDammV2Pool, getDammV2RemainingAccounts, getDlmmRemainingAccounts, getExtraAccountMetasForTransferHook, getJupiterQuote, getJupiterSwapInstruction, getLbPairState, getNextBinArrayIndexWithLiquidity, getOrCreateATAInstruction, getTokenProgramFromMint, unwrapSOLInstruction, wrapSOLInstruction };
|
|
390
|
+
export { AMOUNT_IN_DAMM_V2_OFFSET, AMOUNT_IN_DLMM_OFFSET, AMOUNT_IN_JUP_V6_REVERSE_OFFSET, AccountsType, BIN_ARRAY_INDEX_BOUND, DAMM_V2_PROGRAM_ID, DAMM_V2_SWAP_DISCRIMINATOR, DLMM_PROGRAM_ID, DLMM_SWAP_DISCRIMINATOR, JUP_V6_PROGRAM_ID, type JupiterInstruction, type JupiterQuoteResponse, type JupiterRoutePlan, type JupiterSwapInstructionResponse, MEMO_PROGRAM_ID, ZAP_PROGRAM_ID, Zap, type ZapOutParameters, type ZapOutParams, type ZapOutThroughDammV2Params, type ZapOutThroughDlmmParams, type ZapOutThroughJupiterParams, type ZapProgram, convertAccountTypeToNumber, createDammV2SwapPayload, createDlmmSwapPayload, deriveDammV2EventAuthority, getBinArrayBitmapExtension, getBitFromBinArrayIndexInBitmapExtension, getDammV2Pool, getDammV2RemainingAccounts, getDlmmRemainingAccounts, getExtraAccountMetasForTransferHook, getJupiterQuote, getJupiterSwapInstruction, getLbPairState, getNextBinArrayIndexWithLiquidity, getOrCreateATAInstruction, getTokenAccountBalance, getTokenProgramFromMint, unwrapSOLInstruction, wrapSOLInstruction };
|
package/dist/index.d.ts
CHANGED
|
@@ -320,6 +320,13 @@ declare const getOrCreateATAInstruction: (connection: Connection, tokenMint: Pub
|
|
|
320
320
|
* @returns The unwrap SOL instruction
|
|
321
321
|
*/
|
|
322
322
|
declare function unwrapSOLInstruction(owner: PublicKey, receiver: PublicKey, allowOwnerOffCurve?: boolean): TransactionInstruction | null;
|
|
323
|
+
/**
|
|
324
|
+
* Get token account balance
|
|
325
|
+
* @param connection - Solana connection
|
|
326
|
+
* @param tokenAccount - The token account address
|
|
327
|
+
* @returns The token account balance as a string
|
|
328
|
+
*/
|
|
329
|
+
declare function getTokenAccountBalance(connection: Connection, tokenAccount: PublicKey): Promise<string>;
|
|
323
330
|
/**
|
|
324
331
|
* Wrap SOL instruction
|
|
325
332
|
* @param from - The from address
|
|
@@ -380,4 +387,4 @@ declare const AMOUNT_IN_JUP_V6_REVERSE_OFFSET = 19;
|
|
|
380
387
|
declare const AMOUNT_IN_DAMM_V2_OFFSET = 8;
|
|
381
388
|
declare const DAMM_V2_SWAP_DISCRIMINATOR: number[];
|
|
382
389
|
|
|
383
|
-
export { AMOUNT_IN_DAMM_V2_OFFSET, AMOUNT_IN_DLMM_OFFSET, AMOUNT_IN_JUP_V6_REVERSE_OFFSET, AccountsType, BIN_ARRAY_INDEX_BOUND, DAMM_V2_PROGRAM_ID, DAMM_V2_SWAP_DISCRIMINATOR, DLMM_PROGRAM_ID, DLMM_SWAP_DISCRIMINATOR, JUP_V6_PROGRAM_ID, type JupiterInstruction, type JupiterQuoteResponse, type JupiterRoutePlan, type JupiterSwapInstructionResponse, MEMO_PROGRAM_ID, ZAP_PROGRAM_ID, Zap, type ZapOutParameters, type ZapOutParams, type ZapOutThroughDammV2Params, type ZapOutThroughDlmmParams, type ZapOutThroughJupiterParams, type ZapProgram, convertAccountTypeToNumber, createDammV2SwapPayload, createDlmmSwapPayload, deriveDammV2EventAuthority, getBinArrayBitmapExtension, getBitFromBinArrayIndexInBitmapExtension, getDammV2Pool, getDammV2RemainingAccounts, getDlmmRemainingAccounts, getExtraAccountMetasForTransferHook, getJupiterQuote, getJupiterSwapInstruction, getLbPairState, getNextBinArrayIndexWithLiquidity, getOrCreateATAInstruction, getTokenProgramFromMint, unwrapSOLInstruction, wrapSOLInstruction };
|
|
390
|
+
export { AMOUNT_IN_DAMM_V2_OFFSET, AMOUNT_IN_DLMM_OFFSET, AMOUNT_IN_JUP_V6_REVERSE_OFFSET, AccountsType, BIN_ARRAY_INDEX_BOUND, DAMM_V2_PROGRAM_ID, DAMM_V2_SWAP_DISCRIMINATOR, DLMM_PROGRAM_ID, DLMM_SWAP_DISCRIMINATOR, JUP_V6_PROGRAM_ID, type JupiterInstruction, type JupiterQuoteResponse, type JupiterRoutePlan, type JupiterSwapInstructionResponse, MEMO_PROGRAM_ID, ZAP_PROGRAM_ID, Zap, type ZapOutParameters, type ZapOutParams, type ZapOutThroughDammV2Params, type ZapOutThroughDlmmParams, type ZapOutThroughJupiterParams, type ZapProgram, convertAccountTypeToNumber, createDammV2SwapPayload, createDlmmSwapPayload, deriveDammV2EventAuthority, getBinArrayBitmapExtension, getBitFromBinArrayIndexInBitmapExtension, getDammV2Pool, getDammV2RemainingAccounts, getDlmmRemainingAccounts, getExtraAccountMetasForTransferHook, getJupiterQuote, getJupiterSwapInstruction, getLbPairState, getNextBinArrayIndexWithLiquidity, getOrCreateATAInstruction, getTokenAccountBalance, getTokenProgramFromMint, unwrapSOLInstruction, wrapSOLInstruction };
|
package/dist/index.js
CHANGED
|
@@ -95,6 +95,7 @@ __export(index_exports, {
|
|
|
95
95
|
getLbPairState: () => getLbPairState,
|
|
96
96
|
getNextBinArrayIndexWithLiquidity: () => getNextBinArrayIndexWithLiquidity,
|
|
97
97
|
getOrCreateATAInstruction: () => getOrCreateATAInstruction,
|
|
98
|
+
getTokenAccountBalance: () => getTokenAccountBalance,
|
|
98
99
|
getTokenProgramFromMint: () => getTokenProgramFromMint,
|
|
99
100
|
unwrapSOLInstruction: () => unwrapSOLInstruction,
|
|
100
101
|
wrapSOLInstruction: () => wrapSOLInstruction
|
|
@@ -496,6 +497,11 @@ function unwrapSOLInstruction(owner, receiver, allowOwnerOffCurve = true) {
|
|
|
496
497
|
}
|
|
497
498
|
return null;
|
|
498
499
|
}
|
|
500
|
+
function getTokenAccountBalance(connection, tokenAccount) {
|
|
501
|
+
return __async(this, null, function* () {
|
|
502
|
+
return (yield connection.getTokenAccountBalance(tokenAccount)).value.amount;
|
|
503
|
+
});
|
|
504
|
+
}
|
|
499
505
|
function wrapSOLInstruction(from, to, amount, tokenProgram = import_spl_token3.TOKEN_PROGRAM_ID) {
|
|
500
506
|
return [
|
|
501
507
|
import_web34.SystemProgram.transfer({
|
|
@@ -896,7 +902,17 @@ var Zap = class {
|
|
|
896
902
|
]);
|
|
897
903
|
inputTokenAccountIx && preInstructions.push(inputTokenAccountIx);
|
|
898
904
|
outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
|
|
899
|
-
|
|
905
|
+
if (inputMint.equals(import_spl_token5.NATIVE_MINT)) {
|
|
906
|
+
const wrapIxs = wrapSOLInstruction(
|
|
907
|
+
user,
|
|
908
|
+
inputTokenAccount,
|
|
909
|
+
BigInt(maxSwapAmount.toString())
|
|
910
|
+
);
|
|
911
|
+
if (wrapIxs) {
|
|
912
|
+
preInstructions.push(...wrapIxs);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
const preUserTokenBalance = inputTokenAccountIx ? "0" : yield getTokenAccountBalance(this.connection, inputTokenAccount);
|
|
900
916
|
const remainingAccounts = jupiterSwapResponse.swapInstruction.accounts.map(
|
|
901
917
|
(account) => {
|
|
902
918
|
let pubkey = typeof account.pubkey === "string" ? new import_web37.PublicKey(account.pubkey) : account.pubkey;
|
|
@@ -988,7 +1004,17 @@ var Zap = class {
|
|
|
988
1004
|
]);
|
|
989
1005
|
inputTokenAccountIx && preInstructions.push(inputTokenAccountIx);
|
|
990
1006
|
outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
|
|
991
|
-
|
|
1007
|
+
if (inputMint.equals(import_spl_token5.NATIVE_MINT)) {
|
|
1008
|
+
const wrapIxs = wrapSOLInstruction(
|
|
1009
|
+
user,
|
|
1010
|
+
inputTokenAccount,
|
|
1011
|
+
BigInt(maxSwapAmount.toString())
|
|
1012
|
+
);
|
|
1013
|
+
if (wrapIxs) {
|
|
1014
|
+
preInstructions.push(...wrapIxs);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
const preUserTokenBalance = inputTokenAccountIx ? "0" : yield getTokenAccountBalance(this.connection, inputTokenAccount);
|
|
992
1018
|
const remainingAccounts = yield getDammV2RemainingAccounts(
|
|
993
1019
|
poolAddress,
|
|
994
1020
|
user,
|
|
@@ -1076,7 +1102,17 @@ var Zap = class {
|
|
|
1076
1102
|
]);
|
|
1077
1103
|
inputTokenAccountIx && preInstructions.push(inputTokenAccountIx);
|
|
1078
1104
|
outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
|
|
1079
|
-
|
|
1105
|
+
if (inputMint.equals(import_spl_token5.NATIVE_MINT)) {
|
|
1106
|
+
const wrapIxs = wrapSOLInstruction(
|
|
1107
|
+
user,
|
|
1108
|
+
inputTokenAccount,
|
|
1109
|
+
BigInt(maxSwapAmount.toString())
|
|
1110
|
+
);
|
|
1111
|
+
if (wrapIxs) {
|
|
1112
|
+
preInstructions.push(...wrapIxs);
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
const preUserTokenBalance = inputTokenAccountIx ? "0" : yield getTokenAccountBalance(this.connection, inputTokenAccount);
|
|
1080
1116
|
const { remainingAccounts, remainingAccountsInfo } = yield getDlmmRemainingAccounts(
|
|
1081
1117
|
this.connection,
|
|
1082
1118
|
lbPairAddress,
|
|
@@ -1145,6 +1181,7 @@ var Zap = class {
|
|
|
1145
1181
|
getLbPairState,
|
|
1146
1182
|
getNextBinArrayIndexWithLiquidity,
|
|
1147
1183
|
getOrCreateATAInstruction,
|
|
1184
|
+
getTokenAccountBalance,
|
|
1148
1185
|
getTokenProgramFromMint,
|
|
1149
1186
|
unwrapSOLInstruction,
|
|
1150
1187
|
wrapSOLInstruction
|
package/dist/index.mjs
CHANGED
|
@@ -453,6 +453,11 @@ function unwrapSOLInstruction(owner, receiver, allowOwnerOffCurve = true) {
|
|
|
453
453
|
}
|
|
454
454
|
return null;
|
|
455
455
|
}
|
|
456
|
+
function getTokenAccountBalance(connection, tokenAccount) {
|
|
457
|
+
return __async(this, null, function* () {
|
|
458
|
+
return (yield connection.getTokenAccountBalance(tokenAccount)).value.amount;
|
|
459
|
+
});
|
|
460
|
+
}
|
|
456
461
|
function wrapSOLInstruction(from, to, amount, tokenProgram = TOKEN_PROGRAM_ID3) {
|
|
457
462
|
return [
|
|
458
463
|
SystemProgram.transfer({
|
|
@@ -866,7 +871,17 @@ var Zap = class {
|
|
|
866
871
|
]);
|
|
867
872
|
inputTokenAccountIx && preInstructions.push(inputTokenAccountIx);
|
|
868
873
|
outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
|
|
869
|
-
|
|
874
|
+
if (inputMint.equals(NATIVE_MINT3)) {
|
|
875
|
+
const wrapIxs = wrapSOLInstruction(
|
|
876
|
+
user,
|
|
877
|
+
inputTokenAccount,
|
|
878
|
+
BigInt(maxSwapAmount.toString())
|
|
879
|
+
);
|
|
880
|
+
if (wrapIxs) {
|
|
881
|
+
preInstructions.push(...wrapIxs);
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
const preUserTokenBalance = inputTokenAccountIx ? "0" : yield getTokenAccountBalance(this.connection, inputTokenAccount);
|
|
870
885
|
const remainingAccounts = jupiterSwapResponse.swapInstruction.accounts.map(
|
|
871
886
|
(account) => {
|
|
872
887
|
let pubkey = typeof account.pubkey === "string" ? new PublicKey7(account.pubkey) : account.pubkey;
|
|
@@ -958,7 +973,17 @@ var Zap = class {
|
|
|
958
973
|
]);
|
|
959
974
|
inputTokenAccountIx && preInstructions.push(inputTokenAccountIx);
|
|
960
975
|
outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
|
|
961
|
-
|
|
976
|
+
if (inputMint.equals(NATIVE_MINT3)) {
|
|
977
|
+
const wrapIxs = wrapSOLInstruction(
|
|
978
|
+
user,
|
|
979
|
+
inputTokenAccount,
|
|
980
|
+
BigInt(maxSwapAmount.toString())
|
|
981
|
+
);
|
|
982
|
+
if (wrapIxs) {
|
|
983
|
+
preInstructions.push(...wrapIxs);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
const preUserTokenBalance = inputTokenAccountIx ? "0" : yield getTokenAccountBalance(this.connection, inputTokenAccount);
|
|
962
987
|
const remainingAccounts = yield getDammV2RemainingAccounts(
|
|
963
988
|
poolAddress,
|
|
964
989
|
user,
|
|
@@ -1046,7 +1071,17 @@ var Zap = class {
|
|
|
1046
1071
|
]);
|
|
1047
1072
|
inputTokenAccountIx && preInstructions.push(inputTokenAccountIx);
|
|
1048
1073
|
outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
|
|
1049
|
-
|
|
1074
|
+
if (inputMint.equals(NATIVE_MINT3)) {
|
|
1075
|
+
const wrapIxs = wrapSOLInstruction(
|
|
1076
|
+
user,
|
|
1077
|
+
inputTokenAccount,
|
|
1078
|
+
BigInt(maxSwapAmount.toString())
|
|
1079
|
+
);
|
|
1080
|
+
if (wrapIxs) {
|
|
1081
|
+
preInstructions.push(...wrapIxs);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
const preUserTokenBalance = inputTokenAccountIx ? "0" : yield getTokenAccountBalance(this.connection, inputTokenAccount);
|
|
1050
1085
|
const { remainingAccounts, remainingAccountsInfo } = yield getDlmmRemainingAccounts(
|
|
1051
1086
|
this.connection,
|
|
1052
1087
|
lbPairAddress,
|
|
@@ -1114,6 +1149,7 @@ export {
|
|
|
1114
1149
|
getLbPairState,
|
|
1115
1150
|
getNextBinArrayIndexWithLiquidity,
|
|
1116
1151
|
getOrCreateATAInstruction,
|
|
1152
|
+
getTokenAccountBalance,
|
|
1117
1153
|
getTokenProgramFromMint,
|
|
1118
1154
|
unwrapSOLInstruction,
|
|
1119
1155
|
wrapSOLInstruction
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meteora-ag/zap-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
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",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/bn.js": "^5.1.0",
|
|
29
29
|
"@types/bun": "latest",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
30
|
+
"tsup": "^8.4.0",
|
|
31
|
+
"tsx": "^4.20.3"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"typescript": "^5"
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
"@solana/spl-token": "^0.4.13",
|
|
41
41
|
"@solana/web3.js": "^1.98.2",
|
|
42
42
|
"bn.js": "^5.2.2",
|
|
43
|
-
"decimal.js": "^10.4.2"
|
|
43
|
+
"decimal.js": "^10.4.2",
|
|
44
|
+
"jito-ts": "^4.2.0"
|
|
44
45
|
},
|
|
45
46
|
"scripts": {
|
|
46
47
|
"build": "rm -rf dist && tsup src/index.ts --format esm,cjs --dts",
|